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

update upload hf

Browse files
app/services/video_processing/hf_upload.py CHANGED
@@ -1,3 +1,12 @@
 
 
 
 
 
 
 
 
 
1
 
2
  def _ensure_repo_exists(self):
3
  try:
@@ -18,4 +27,31 @@
18
  if "You already created this dataset repo" not in str(create_error):
19
  raise create_error
20
  else:
21
- raise e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
11
  def _ensure_repo_exists(self):
12
  try:
 
27
  if "You already created this dataset repo" not in str(create_error):
28
  raise create_error
29
  else:
30
+ raise e
31
+
32
+ def ensure_folder_structure(self, sport_id: str):
33
+ paths = [
34
+ f"{sport_id}/raw",
35
+ f"{sport_id}/compressed"
36
+ ]
37
+ for path in paths:
38
+ try:
39
+ self.hf_api.upload_file(
40
+ path_or_fileobj="",
41
+ path_in_repo=f"{path}/.gitkeep",
42
+ repo_id=self.repo_id,
43
+ repo_type="dataset",
44
+ token=os.getenv("HUGGINGFACE_TOKEN")
45
+ )
46
+ except Exception:
47
+ pass
48
+
49
+ def upload_video(self, file_path: str, destination_path: str):
50
+ self.hf_api.upload_file(
51
+ path_or_fileobj=file_path,
52
+ path_in_repo=destination_path,
53
+ repo_id=self.repo_id,
54
+ repo_type="dataset",
55
+ token=os.getenv("HUGGINGFACE_TOKEN")
56
+ )
57
+ return f"https://huggingface.co/datasets/{self.repo_id}/raw/main/{destination_path}"