Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -235,7 +235,6 @@
|
|
235 |
# # http://localhost:8000/docs#/
|
236 |
# # (.venv) PS C:\Users\antoi\Documents\Work_Learn\Labeling-Deploy\FastAPI> uvicorn main:app --host 0.0.0.0 --port 8000 --workers 1
|
237 |
|
238 |
-
|
239 |
from fastapi import FastAPI, UploadFile, File, HTTPException
|
240 |
import cv2
|
241 |
import torch
|
@@ -452,6 +451,40 @@ def convertir_sequences_en_json(dataframe):
|
|
452 |
|
453 |
|
454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
455 |
|
456 |
@app.post("/upload_video/")
|
457 |
async def upload_video(user_name: str, file: UploadFile = File(...)):
|
|
|
235 |
# # http://localhost:8000/docs#/
|
236 |
# # (.venv) PS C:\Users\antoi\Documents\Work_Learn\Labeling-Deploy\FastAPI> uvicorn main:app --host 0.0.0.0 --port 8000 --workers 1
|
237 |
|
|
|
238 |
from fastapi import FastAPI, UploadFile, File, HTTPException
|
239 |
import cv2
|
240 |
import torch
|
|
|
451 |
|
452 |
|
453 |
|
454 |
+
# Endpoint pour analyser la vidéo à partir d'une URL
|
455 |
+
@app.post("/analyze_video/")
|
456 |
+
async def analyze_video(user_name: str, video_url: Optional[str] = None):
|
457 |
+
try:
|
458 |
+
# Log for debugging purposes
|
459 |
+
print(f"Received user_name: {user_name}")
|
460 |
+
print(f"Received video_url: {video_url}")
|
461 |
+
|
462 |
+
# Assurez-vous d'avoir une URL valide à ce stade
|
463 |
+
if not video_url:
|
464 |
+
raise HTTPException(status_code=400, detail="No valid video URL provided.")
|
465 |
+
|
466 |
+
# Télécharge la vidéo temporairement pour l'analyser
|
467 |
+
temp_file_path = "/tmp/video_to_analyze.mp4"
|
468 |
+
os.system(f"wget -O {temp_file_path} {video_url}")
|
469 |
+
|
470 |
+
# Analyser la vidéo via l'URL
|
471 |
+
dataframe_sequences = identifier_sequences_surfing(temp_file_path, intervalle=1)
|
472 |
+
json_result = convertir_sequences_en_json(dataframe_sequences)
|
473 |
+
|
474 |
+
# Supprimer la vidéo temporaire après l'analyse
|
475 |
+
os.remove(temp_file_path)
|
476 |
+
|
477 |
+
return {
|
478 |
+
"message": "Video analyzed successfully!",
|
479 |
+
"file_url": video_url,
|
480 |
+
"analysis": json_result
|
481 |
+
}
|
482 |
+
|
483 |
+
except Exception as e:
|
484 |
+
print(f"Error during video analysis: {str(e)}") # Log the error
|
485 |
+
raise HTTPException(status_code=500, detail=f"Failed to analyze video: {str(e)}")
|
486 |
+
|
487 |
+
|
488 |
|
489 |
@app.post("/upload_video/")
|
490 |
async def upload_video(user_name: str, file: UploadFile = File(...)):
|