2nzi commited on
Commit
9bbcd56
·
verified ·
1 Parent(s): 973ccc4

update app

Browse files
Files changed (1) hide show
  1. app.py +34 -21
app.py CHANGED
@@ -235,6 +235,7 @@
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,30 +452,42 @@ def convertir_sequences_en_json(dataframe):
451
 
452
 
453
 
454
- @app.post("/analyze_video/")
455
- async def analyze_video(user_name: str, video_url: Optional[str] = None):
 
456
  try:
457
- # Log for debugging purposes
458
- print(f"Received user_name: {user_name}")
459
- print(f"Received video_url: {video_url}")
460
-
461
- # Assurez-vous d'avoir une URL valide à ce stade
462
- if not video_url:
463
- raise HTTPException(status_code=400, detail="No valid video URL provided.")
464
-
465
- # Analyser la vidéo via l'URL
466
- dataframe_sequences = identifier_sequences_surfing(video_url, intervalle=1)
467
- json_result = convertir_sequences_en_json(dataframe_sequences)
468
-
469
- return {
470
- "message": "Video analyzed successfully!",
471
- "file_url": video_url,
472
- "analysis": json_result
473
- }
 
 
 
 
 
 
 
 
 
474
 
475
  except Exception as e:
476
- print(f"Error during video analysis: {str(e)}") # Log the error
477
- raise HTTPException(status_code=500, detail=f"Failed to analyze video: {str(e)}")
 
 
478
 
479
 
480
  # Fonction pour uploader une vidéo vers un dataset Hugging Face
 
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
 
453
 
454
 
455
+
456
+ @app.post("/upload_video/")
457
+ async def upload_video(user_name: str, file: UploadFile = File(...)):
458
  try:
459
+ print(f"Received request to upload video for user: {user_name}")
460
+
461
+ # Sauvegarder le fichier temporairement
462
+ temp_file_path = f"/tmp/{file.filename}"
463
+ with open(temp_file_path, "wb") as buffer:
464
+ buffer.write(await file.read())
465
+
466
+ # Préparer l'upload sur Hugging Face
467
+ dataset_name = "2nzi/Video-Sequence-Labeling"
468
+ repo_path = f"{user_name}/raw/{file.filename}"
469
+
470
+ print(f"Uploading {temp_file_path} to Hugging Face at {repo_path}")
471
+
472
+ hf_api.upload_file(
473
+ path_or_fileobj=temp_file_path,
474
+ path_in_repo=repo_path,
475
+ repo_id=dataset_name,
476
+ repo_type="dataset",
477
+ token=api_key
478
+ )
479
+
480
+ # Générer l'URL finale
481
+ file_url = f"https://huggingface.co/datasets/{dataset_name}/resolve/main/{repo_path}"
482
+ print(f"File successfully uploaded to: {file_url}")
483
+
484
+ return {"status": "success", "file_url": file_url}
485
 
486
  except Exception as e:
487
+ print(f"Error during upload: {str(e)}")
488
+ raise HTTPException(status_code=500, detail=f"Upload failed: {str(e)}")
489
+
490
+
491
 
492
 
493
  # Fonction pour uploader une vidéo vers un dataset Hugging Face