-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (31 loc) · 1.21 KB
/
main.py
File metadata and controls
47 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.encoders import jsonable_encoder
import json
app = FastAPI()
import tensorflow as tf
classification_model = tf.keras.models.load_model('./space_classification/space_classification_model/space_resnet50model_blur.hdf5')
class Item(BaseModel):
name: Union[str, None] = None
price: Union[float, None] = None
url: str
is_offer: Union[bool, None] = None
@app.get("/")
def read_root():
return {"Hello": "World"}
from space_classification.space_classification import space_classification, img_download
@app.put("/test")
def test_model(item: Item):
url = item.url
image_path = img_download(url)
category, score = space_classification(image_path, classification_model)
category_int_lst = list([int(x) for x in category])
score_float_lst = list([float(x) for x in score])
return {"lifing": category_int_lst, "score": score_float_lst}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
return {"item_name": item.price, "item_id": item_id}