2nzi commited on
Commit
664dec8
·
verified ·
1 Parent(s): ce73fe4

update upload hf

Browse files
app/services/video_processing/hf_upload.py CHANGED
@@ -1,42 +1,21 @@
1
- from huggingface_hub import HfApi, create_repo
2
- import os
3
-
4
- class HFUploader:
5
- def __init__(self):
6
- self.hf_api = HfApi()
7
- self.repo_id = "HUGGINGFACE_REPO_ID"
8
- self._ensure_repo_exists()
9
-
10
- def _ensure_repo_exists(self):
11
- try:
12
- self.hf_api.repo_info(repo_id=self.repo_id, repo_type="dataset")
13
- except Exception:
14
- create_repo(self.repo_id, private=False, repo_type="dataset",
15
- token=os.getenv("HUGGINGFACE_TOKEN"))
16
-
17
- def ensure_folder_structure(self, sport_id: str):
18
- paths = [
19
- f"{sport_id}/raw",
20
- f"{sport_id}/compressed"
21
- ]
22
- for path in paths:
23
- try:
24
- self.hf_api.upload_file(
25
- path_or_fileobj="",
26
- path_in_repo=f"{path}/.gitkeep",
27
- repo_id=self.repo_id,
28
- repo_type="dataset",
29
- token=os.getenv("HUGGINGFACE_TOKEN")
30
- )
31
- except Exception:
32
- pass
33
-
34
- def upload_video(self, file_path: str, destination_path: str):
35
- self.hf_api.upload_file(
36
- path_or_fileobj=file_path,
37
- path_in_repo=destination_path,
38
- repo_id=self.repo_id,
39
- repo_type="dataset",
40
- token=os.getenv("HUGGINGFACE_TOKEN")
41
- )
42
- return f"https://huggingface.co/datasets/{self.repo_id}/raw/main/{destination_path}"
 
1
+
2
+ def _ensure_repo_exists(self):
3
+ try:
4
+ # Vérifie si le repo existe
5
+ self.hf_api.repo_info(repo_id=self.repo_id, repo_type="dataset")
6
+ print(f"Repository {self.repo_id} exists")
7
+ except Exception as e:
8
+ if "404" in str(e): # Repo n'existe pas
9
+ try:
10
+ create_repo(
11
+ self.repo_id,
12
+ private=False,
13
+ repo_type="dataset",
14
+ token=os.getenv("HUGGINGFACE_TOKEN")
15
+ )
16
+ print(f"Created repository {self.repo_id}")
17
+ except Exception as create_error:
18
+ if "You already created this dataset repo" not in str(create_error):
19
+ raise create_error
20
+ else:
21
+ raise e