Spaces:
Sleeping
Sleeping
update app
Browse files
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 |
-
|
455 |
-
|
|
|
456 |
try:
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
|
475 |
except Exception as e:
|
476 |
-
print(f"Error during
|
477 |
-
raise HTTPException(status_code=500, detail=f"
|
|
|
|
|
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
|