Spaces:
Running
Running
Update Summarization/main.py
Browse files- Summarization/main.py +8 -7
Summarization/main.py
CHANGED
@@ -18,31 +18,32 @@ app.add_middleware(
|
|
18 |
allow_headers=["*"],
|
19 |
)
|
20 |
|
21 |
-
#
|
22 |
current_dir = Path(__file__).parent
|
23 |
templates = Jinja2Templates(directory=current_dir.parent / "templates")
|
24 |
|
25 |
-
|
|
|
26 |
async def serve_home(request: Request):
|
27 |
return templates.TemplateResponse("HomeS.html", {"request": request})
|
28 |
|
29 |
-
@app.post("
|
30 |
async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
|
31 |
try:
|
32 |
result = await summarize_document(file, length)
|
33 |
return JSONResponse(result)
|
34 |
except Exception as e:
|
35 |
-
return JSONResponse({"detail":
|
36 |
|
37 |
-
@app.post("
|
38 |
async def caption(file: UploadFile = File(...)):
|
39 |
try:
|
40 |
result = await caption_image(file)
|
41 |
return JSONResponse(result)
|
42 |
except Exception as e:
|
43 |
-
return JSONResponse({"error":
|
44 |
|
45 |
-
@app.get("
|
46 |
async def serve_file(filename: str):
|
47 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
48 |
if os.path.exists(filepath):
|
|
|
18 |
allow_headers=["*"],
|
19 |
)
|
20 |
|
21 |
+
# Dynamic template path
|
22 |
current_dir = Path(__file__).parent
|
23 |
templates = Jinja2Templates(directory=current_dir.parent / "templates")
|
24 |
|
25 |
+
# Note: No leading slashes in routes
|
26 |
+
@app.get("", response_class=HTMLResponse) # Handles /summarization/
|
27 |
async def serve_home(request: Request):
|
28 |
return templates.TemplateResponse("HomeS.html", {"request": request})
|
29 |
|
30 |
+
@app.post("summarize/") # Handles /summarization/summarize/
|
31 |
async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
|
32 |
try:
|
33 |
result = await summarize_document(file, length)
|
34 |
return JSONResponse(result)
|
35 |
except Exception as e:
|
36 |
+
return JSONResponse({"detail": str(e)}, status_code=500)
|
37 |
|
38 |
+
@app.post("imagecaption/") # Handles /summarization/imagecaption/
|
39 |
async def caption(file: UploadFile = File(...)):
|
40 |
try:
|
41 |
result = await caption_image(file)
|
42 |
return JSONResponse(result)
|
43 |
except Exception as e:
|
44 |
+
return JSONResponse({"error": str(e)}, status_code=500)
|
45 |
|
46 |
+
@app.get("files/{filename}") # Handles /summarization/files/{filename}
|
47 |
async def serve_file(filename: str):
|
48 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
49 |
if os.path.exists(filepath):
|