Spaces:
Sleeping
Sleeping
Update Summarization/main.py
Browse files- Summarization/main.py +19 -9
Summarization/main.py
CHANGED
@@ -4,9 +4,7 @@ from fastapi.templating import Jinja2Templates
|
|
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 |
|
@@ -21,7 +19,7 @@ app.add_middleware(
|
|
21 |
current_dir = Path(__file__).parent
|
22 |
templates = Jinja2Templates(directory=current_dir.parent / "templates")
|
23 |
|
24 |
-
@app.get("/", response_class=HTMLResponse)
|
25 |
async def serve_home(request: Request):
|
26 |
return templates.TemplateResponse("HomeS.html", {"request": request})
|
27 |
|
@@ -41,9 +39,21 @@ async def caption(file: UploadFile = File(...)):
|
|
41 |
except Exception as e:
|
42 |
return JSONResponse({"error": str(e)}, status_code=500)
|
43 |
|
44 |
-
@app.get("/files/{filename}")
|
45 |
-
async def serve_file(filename: str):
|
46 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
import tempfile, os
|
6 |
from pathlib import Path
|
7 |
+
import mimetypes
|
|
|
|
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
|
|
19 |
current_dir = Path(__file__).parent
|
20 |
templates = Jinja2Templates(directory=current_dir.parent / "templates")
|
21 |
|
22 |
+
@app.get("/", response_class=HTMLResponse)
|
23 |
async def serve_home(request: Request):
|
24 |
return templates.TemplateResponse("HomeS.html", {"request": request})
|
25 |
|
|
|
39 |
except Exception as e:
|
40 |
return JSONResponse({"error": str(e)}, status_code=500)
|
41 |
|
42 |
+
@app.get("/files/{filename}")
|
43 |
+
async def serve_file(filename: str, request: Request):
|
44 |
filepath = os.path.join(tempfile.gettempdir(), filename)
|
45 |
+
|
46 |
+
if not os.path.exists(filepath):
|
47 |
+
return JSONResponse({"error": "File not found"}, status_code=404)
|
48 |
+
|
49 |
+
# Determine correct media type and set attachment disposition
|
50 |
+
media_type, _ = mimetypes.guess_type(filepath)
|
51 |
+
if media_type is None:
|
52 |
+
media_type = "application/octet-stream"
|
53 |
+
|
54 |
+
return FileResponse(
|
55 |
+
filepath,
|
56 |
+
media_type=media_type,
|
57 |
+
filename=filename,
|
58 |
+
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
59 |
+
)
|