Spaces:
Sleeping
Sleeping
update upload hf
Browse files
app/services/video_processing/hf_upload.py
CHANGED
@@ -1,42 +1,21 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|