-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
30 lines (22 loc) Β· 1.01 KB
/
main.py
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
from fastapi import FastAPI, HTTPException, Request
from video_downloader import download_video
from frame_extractor import extract_frames
from model_predictor import predict_posture
from result_analyzer import analyze_results
import os
app = FastAPI()
@app.post("/predict")
async def predict(video_data: dict):
try:
video_url = video_data.get("video_url")
if not video_url:
raise HTTPException(status_code=400, detail="Missing video_url in request body")
video_file = await download_video(video_url)
if video_file is None:
raise HTTPException(status_code=400, detail="Video download failed")
images, landmarks_info, status_frequencies = extract_frames(video_file)
result, scores, hunched_ratio, normal_ratio = predict_posture(images)
os.remove(video_file)
return analyze_results(result, scores, hunched_ratio, normal_ratio, landmarks_info, status_frequencies)
except Exception as e:
return {"error": str(e)}