Spaces:
Sleeping
Sleeping
Update Summarization/main.py
Browse files- Summarization/main.py +5 -7
Summarization/main.py
CHANGED
|
@@ -18,16 +18,14 @@ app.add_middleware(
|
|
| 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 |
-
#
|
| 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/")
|
| 31 |
async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
|
| 32 |
try:
|
| 33 |
result = await summarize_document(file, length)
|
|
@@ -35,7 +33,7 @@ async def summarize_api(file: UploadFile = File(...), length: str = Form("medium
|
|
| 35 |
except Exception as e:
|
| 36 |
return JSONResponse({"detail": str(e)}, status_code=500)
|
| 37 |
|
| 38 |
-
@app.post("/imagecaption/")
|
| 39 |
async def caption(file: UploadFile = File(...)):
|
| 40 |
try:
|
| 41 |
result = await caption_image(file)
|
|
@@ -43,9 +41,9 @@ async def caption(file: UploadFile = File(...)):
|
|
| 43 |
except Exception as e:
|
| 44 |
return JSONResponse({"error": str(e)}, status_code=500)
|
| 45 |
|
| 46 |
-
@app.get("files/{filename}") #
|
| 47 |
async def serve_file(filename: str):
|
| 48 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
| 49 |
if os.path.exists(filepath):
|
| 50 |
return FileResponse(filepath)
|
| 51 |
-
return JSONResponse({"error": "File not found"}, status_code=404)
|
|
|
|
| 18 |
allow_headers=["*"],
|
| 19 |
)
|
| 20 |
|
|
|
|
| 21 |
current_dir = Path(__file__).parent
|
| 22 |
templates = Jinja2Templates(directory=current_dir.parent / "templates")
|
| 23 |
|
| 24 |
+
@app.get("/", response_class=HTMLResponse) # ✅ Corrected
|
|
|
|
| 25 |
async def serve_home(request: Request):
|
| 26 |
return templates.TemplateResponse("HomeS.html", {"request": request})
|
| 27 |
|
| 28 |
+
@app.post("/summarize/")
|
| 29 |
async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
|
| 30 |
try:
|
| 31 |
result = await summarize_document(file, length)
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return JSONResponse({"detail": str(e)}, status_code=500)
|
| 35 |
|
| 36 |
+
@app.post("/imagecaption/")
|
| 37 |
async def caption(file: UploadFile = File(...)):
|
| 38 |
try:
|
| 39 |
result = await caption_image(file)
|
|
|
|
| 41 |
except Exception as e:
|
| 42 |
return JSONResponse({"error": str(e)}, status_code=500)
|
| 43 |
|
| 44 |
+
@app.get("/files/{filename}") # ✅ Corrected
|
| 45 |
async def serve_file(filename: str):
|
| 46 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
| 47 |
if os.path.exists(filepath):
|
| 48 |
return FileResponse(filepath)
|
| 49 |
+
return JSONResponse({"error": "File not found"}, status_code=404)
|