-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
31 lines (23 loc) · 914 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
import utils
from typing import Optional
from fastapi import FastAPI, File, UploadFile, Request
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/")
def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/")
async def home_predict(request: Request, file: UploadFile = File(...)):
result = None
error = None
try:
result = utils.get_result(image_file=file)
except Exception as ex:
error = ex
return templates.TemplateResponse("index.html", {"request": request, "result": result , "error": error})
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
return utils.get_result(image_file=file, is_api=True)