File size: 1,610 Bytes
d2542a3 9570de2 1579b70 d2542a3 9570de2 9104277 d2542a3 9b5f6c3 9570de2 d2542a3 9104277 87286d5 9104277 87286d5 9104277 87286d5 992f44d 9104277 6a6ee7b 1579b70 6a6ee7b d2542a3 6a6ee7b 87286d5 d2542a3 6a6ee7b d2542a3 9570de2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
from fastapi import APIRouter, UploadFile, File
from fastapi.responses import JSONResponse
from services.extractor import extract_features
from services.summarizer import get_scores, get_selected_indices, save_summary_video
from uuid import uuid4
import time
import os
router = APIRouter()
@router.post("/summarize")
def summarize_video(video: UploadFile = File(...)):
if not video.filename.lower().endswith(('.mp4', '.avi', '.mov', '.mkv')):
return JSONResponse(content={"error": "Unsupported file format"}, status_code=400)
extension = video.filename.split('.')[-1].lower()
id = str(time.time()).replace('.', '_')
filename = f"{id}.{extension}"
processed_filename = f"{id}_processed.{extension}"
filepath = os.path.join(os.getcwd(), "static", filename)
processed_filepath = os.path.join(os.getcwd(), "static", processed_filename)
url = f"/static/{processed_filename}"
print("\n-----------> Saving Video Locally ....")
with open(filepath, "wb") as f:
f.write(video.file.read())
print("\n-----------> Extracting Features ....")
features, picks = extract_features(filepath)
print("\n-----------> Getting Scores ....")
scores = get_scores(features)
print("\n-----------> Selecting Indices ....")
selected = get_selected_indices(scores, picks)
print("\n-----------> Saving Video ....")
save_summary_video(filepath, selected, processed_filepath)
print("\n-----------> Returning Response ....")
return JSONResponse(content={
"message": "Summarization complete",
"summary_video_url": url
}) |