-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (29 loc) · 1.11 KB
/
main.py
File metadata and controls
39 lines (29 loc) · 1.11 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
import os
from fastapi import FastAPI, File, UploadFile, Request
from fastapi.responses import RedirectResponse, HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from model import Model
app = FastAPI()
os.makedirs("static", exist_ok=True)
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
responses = []
model = Model()
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse(
"home.html", {"request": request, "response": responses})
@app.post("/uploadimage/")
async def upload_image(image: UploadFile = File(...)):
file_loc = f"static/{image.filename}"
with open(file_loc, "wb+") as file:
file.write(image.file.read())
# inference and parse
meal_data = model("", image.filename)
# TODO process output and log meal
# debug output just print the parsed data
output = str(meal_data)
# display response
responses.append(output)
return RedirectResponse(url="/", status_code=303)