add code for downloading
Browse files- routes/summarize.py +15 -12
routes/summarize.py
CHANGED
@@ -1,23 +1,14 @@
|
|
1 |
from fastapi import APIRouter, UploadFile, File
|
2 |
-
from fastapi.responses import JSONResponse
|
3 |
from services.extractor import extract_features
|
4 |
from services.summarizer import get_scores, get_selected_indices, save_summary_video
|
5 |
-
from uuid import uuid4
|
6 |
import time
|
7 |
import os
|
8 |
|
9 |
router = APIRouter()
|
10 |
|
11 |
-
@router.post("/summarize")
|
12 |
|
13 |
-
@router.
|
14 |
-
def download_summary(filename: str):
|
15 |
-
file_path = os.path.join(os.getcwd(), "static", filename)
|
16 |
-
return FileResponse(
|
17 |
-
path=file_path,
|
18 |
-
filename=filename,
|
19 |
-
media_type='application/octet-stream'
|
20 |
-
)
|
21 |
def summarize_video(video: UploadFile = File(...)):
|
22 |
if not video.filename.lower().endswith(('.mp4', '.avi', '.mov', '.mkv')):
|
23 |
return JSONResponse(content={"error": "Unsupported file format"}, status_code=400)
|
@@ -29,6 +20,7 @@ def summarize_video(video: UploadFile = File(...)):
|
|
29 |
filepath = os.path.join(os.getcwd(), "static", filename)
|
30 |
processed_filepath = os.path.join(os.getcwd(), "static", processed_filename)
|
31 |
url = f"/static/{processed_filename}"
|
|
|
32 |
|
33 |
print("\n-----------> Saving Video Locally ....")
|
34 |
with open(filepath, "wb") as f:
|
@@ -49,5 +41,16 @@ def summarize_video(video: UploadFile = File(...)):
|
|
49 |
print("\n-----------> Returning Response ....")
|
50 |
return JSONResponse(content={
|
51 |
"message": "Summarization complete",
|
52 |
-
"summary_video_url": url
|
|
|
53 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import APIRouter, UploadFile, File
|
2 |
+
from fastapi.responses import JSONResponse, FileResponse
|
3 |
from services.extractor import extract_features
|
4 |
from services.summarizer import get_scores, get_selected_indices, save_summary_video
|
|
|
5 |
import time
|
6 |
import os
|
7 |
|
8 |
router = APIRouter()
|
9 |
|
|
|
10 |
|
11 |
+
@router.post("/summarize")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def summarize_video(video: UploadFile = File(...)):
|
13 |
if not video.filename.lower().endswith(('.mp4', '.avi', '.mov', '.mkv')):
|
14 |
return JSONResponse(content={"error": "Unsupported file format"}, status_code=400)
|
|
|
20 |
filepath = os.path.join(os.getcwd(), "static", filename)
|
21 |
processed_filepath = os.path.join(os.getcwd(), "static", processed_filename)
|
22 |
url = f"/static/{processed_filename}"
|
23 |
+
download_url = f"/download/{processed_filename}"
|
24 |
|
25 |
print("\n-----------> Saving Video Locally ....")
|
26 |
with open(filepath, "wb") as f:
|
|
|
41 |
print("\n-----------> Returning Response ....")
|
42 |
return JSONResponse(content={
|
43 |
"message": "Summarization complete",
|
44 |
+
"summary_video_url": url,
|
45 |
+
"download_url": download_url
|
46 |
})
|
47 |
+
|
48 |
+
|
49 |
+
@router.get("/download/{filename}")
|
50 |
+
def download_summary(filename: str):
|
51 |
+
file_path = os.path.join(os.getcwd(), "static", filename)
|
52 |
+
return FileResponse(
|
53 |
+
path=file_path,
|
54 |
+
filename=filename,
|
55 |
+
media_type='application/octet-stream'
|
56 |
+
)
|