Spaces:
Sleeping
Sleeping
Update Summarization/main.py
Browse files- Summarization/main.py +13 -20
Summarization/main.py
CHANGED
@@ -4,7 +4,9 @@ from fastapi.templating import Jinja2Templates
|
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
import tempfile, os
|
6 |
from pathlib import Path
|
7 |
-
|
|
|
|
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
@@ -16,14 +18,16 @@ app.add_middleware(
|
|
16 |
allow_headers=["*"],
|
17 |
)
|
18 |
|
|
|
19 |
current_dir = Path(__file__).parent
|
20 |
templates = Jinja2Templates(directory=current_dir.parent / "templates")
|
21 |
|
22 |
-
|
|
|
23 |
async def serve_home(request: Request):
|
24 |
return templates.TemplateResponse("HomeS.html", {"request": request})
|
25 |
|
26 |
-
@app.post("
|
27 |
async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
|
28 |
try:
|
29 |
result = await summarize_document(file, length)
|
@@ -31,7 +35,7 @@ async def summarize_api(file: UploadFile = File(...), length: str = Form("medium
|
|
31 |
except Exception as e:
|
32 |
return JSONResponse({"detail": str(e)}, status_code=500)
|
33 |
|
34 |
-
@app.post("
|
35 |
async def caption(file: UploadFile = File(...)):
|
36 |
try:
|
37 |
result = await caption_image(file)
|
@@ -39,20 +43,9 @@ async def caption(file: UploadFile = File(...)):
|
|
39 |
except Exception as e:
|
40 |
return JSONResponse({"error": str(e)}, status_code=500)
|
41 |
|
42 |
-
@app.get("
|
43 |
-
async def serve_file(filename: str
|
44 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
media_type, _ = mimetypes.guess_type(filepath)
|
50 |
-
if media_type is None:
|
51 |
-
media_type = "application/octet-stream"
|
52 |
-
|
53 |
-
return FileResponse(
|
54 |
-
filepath,
|
55 |
-
media_type=media_type,
|
56 |
-
filename=filename,
|
57 |
-
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
58 |
-
)
|
|
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
import tempfile, os
|
6 |
from pathlib import Path
|
7 |
+
|
8 |
+
from .app import summarize_document
|
9 |
+
from .appImage import caption_image
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
|
|
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)
|
|
|
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)
|
|
|
43 |
except Exception as e:
|
44 |
return JSONResponse({"error": str(e)}, status_code=500)
|
45 |
|
46 |
+
@app.get("files/{filename}") #for download resume as pdf
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|