Spaces:
Sleeping
Sleeping
Update qtAnswering/main.py
Browse files- qtAnswering/main.py +6 -6
qtAnswering/main.py
CHANGED
@@ -5,10 +5,10 @@ from fastapi.templating import Jinja2Templates
|
|
5 |
import shutil, os
|
6 |
from tempfile import gettempdir
|
7 |
|
8 |
-
|
9 |
app = FastAPI()
|
10 |
|
11 |
-
#
|
12 |
app.add_middleware(
|
13 |
CORSMiddleware,
|
14 |
allow_origins=["*"],
|
@@ -17,15 +17,15 @@ app.add_middleware(
|
|
17 |
allow_headers=["*"],
|
18 |
)
|
19 |
|
20 |
-
#
|
21 |
templates = Jinja2Templates(directory="templates")
|
22 |
|
23 |
-
#
|
24 |
@app.get("/", response_class=HTMLResponse)
|
25 |
async def serve_home(request: Request):
|
26 |
return templates.TemplateResponse("home.html", {"request": request})
|
27 |
|
28 |
-
#
|
29 |
@app.post("/predict")
|
30 |
async def predict(question: str = Form(...), file: UploadFile = Form(...)):
|
31 |
try:
|
@@ -60,7 +60,7 @@ async def predict(question: str = Form(...), file: UploadFile = Form(...)):
|
|
60 |
except Exception as e:
|
61 |
return JSONResponse({"error": str(e)}, status_code=500)
|
62 |
|
63 |
-
#
|
64 |
@app.get("/audio/{filename}")
|
65 |
async def get_audio(filename: str):
|
66 |
filepath = os.path.join(gettempdir(), filename)
|
|
|
5 |
import shutil, os
|
6 |
from tempfile import gettempdir
|
7 |
|
8 |
+
|
9 |
app = FastAPI()
|
10 |
|
11 |
+
# CORS middleware
|
12 |
app.add_middleware(
|
13 |
CORSMiddleware,
|
14 |
allow_origins=["*"],
|
|
|
17 |
allow_headers=["*"],
|
18 |
)
|
19 |
|
20 |
+
# Templates
|
21 |
templates = Jinja2Templates(directory="templates")
|
22 |
|
23 |
+
# Serve Homepage
|
24 |
@app.get("/", response_class=HTMLResponse)
|
25 |
async def serve_home(request: Request):
|
26 |
return templates.TemplateResponse("home.html", {"request": request})
|
27 |
|
28 |
+
# Predict endpoint (handles image + document)
|
29 |
@app.post("/predict")
|
30 |
async def predict(question: str = Form(...), file: UploadFile = Form(...)):
|
31 |
try:
|
|
|
60 |
except Exception as e:
|
61 |
return JSONResponse({"error": str(e)}, status_code=500)
|
62 |
|
63 |
+
# Serve audio files
|
64 |
@app.get("/audio/{filename}")
|
65 |
async def get_audio(filename: str):
|
66 |
filepath = os.path.join(gettempdir(), filename)
|