-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmain.py
46 lines (36 loc) · 1.08 KB
/
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
44
45
46
from fastapi import FastAPI, File, UploadFile, Form
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from handlers.processor import process_file
from config import *
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=CORS_ALLOW_ORIGINS,
allow_methods=["*"],
allow_headers=["*"],
)
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/")
def root():
return FileResponse("index.html", media_type="text/html")
@app.get("/favicon.ico")
def favicon():
return FileResponse("favicon.ico")
@app.post("/upload")
async def upload(file: UploadFile = File(...), model: str = Form(default="")):
"""Accepts file and returns its contents."""
try:
contents = await process_file(file, model)
return {
"status": True,
"content": contents,
"error": "",
}
except Exception as e:
return {
"status": False,
"content": "",
"error": str(e),
}