-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (29 loc) · 920 Bytes
/
main.py
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
from fastapi import FastAPI, Request, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from util import load_model, pre_process, post_process
model = load_model()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins="*",
allow_credentials=True,
allow_methods=["POST", "GET"],
allow_headers=["*"],
max_age=3600,
)
@app.post("/upload")
async def create_upload_files(file: UploadFile=File(...)):
image= await file.read()
# Return preprocessed input batch and loaded image
image = pre_process(image)
if image=="Null":
res="neutral"
return res
# Run the model and postpocess the output
prediction = model.predict(image)
# Post process and stitch together the two images to return them
res = post_process(prediction)
return res
@app.get("/")
async def main():
return {"message" : "success"}