|
from fastapi import APIRouter, UploadFile, File |
|
from fastapi.responses import JSONResponse |
|
from utils.file_utils import save_uploaded_file |
|
from services.extractor import extract_frames, extract_features |
|
from services.summarizer import get_scores, get_selected_indices, save_summary_video |
|
from config import UPLOAD_DIR, OUTPUT_DIR |
|
|
|
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) |
|
|
|
print("\n-----------> Uploading Video ....") |
|
video_path = save_uploaded_file(video, UPLOAD_DIR) |
|
|
|
print("\n-----------> Extracting Frames ....") |
|
frames, picks = extract_frames(video_path) |
|
|
|
print("\n-----------> Extracting Features ....") |
|
features = extract_features(frames) |
|
|
|
print("\n-----------> Getting Scores ....") |
|
scores = get_scores(features) |
|
|
|
print("\n-----------> Selecting Indices ....") |
|
selected = get_selected_indices(scores, picks) |
|
output_path = f"{OUTPUT_DIR}/summary_{video.filename}" |
|
|
|
print("\n-----------> Saving Video ....") |
|
save_summary_video(video_path, selected, output_path) |
|
summary_url = f"/static/outputs/summary_{video.filename}" |
|
|
|
print("\n-----------> Returning Response ....") |
|
return JSONResponse(content={ |
|
"message": "Summarization complete", |
|
"summary_video_url": summary_url |
|
}) |
|
|