Fred808 commited on
Commit
6b6503b
·
verified ·
1 Parent(s): 8e0b786

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from huggingface_hub import upload_file
3
+ import os
4
+ from datetime import datetime
5
+
6
+ HF_TOKEN = os.environ.get("HF_TOKEN")
7
+ REPO_ID = "Fred808/BG1"
8
+ DATA_PATH = "Blenders"
9
+
10
+ # Replace this with the actual endpoint that returns list of videos
11
+ LIST_ENDPOINT = "https://fred808-data2.hf.space/files"
12
+ DOWNLOAD_ENDPOINT = "https://fred808-data2.hf.space/download/"
13
+
14
+ def get_video_list():
15
+ try:
16
+ res = requests.get(LIST_ENDPOINT)
17
+ res.raise_for_status()
18
+ return res.json() # Expecting a list of filenames
19
+ except Exception as e:
20
+ print(f"[!] Failed to get video list: {e}")
21
+ return []
22
+
23
+ def download_video(filename):
24
+ try:
25
+ url = f"{DOWNLOAD_ENDPOINT}{filename}"
26
+ res = requests.get(url, stream=True)
27
+ if res.status_code == 200:
28
+ with open(filename, "wb") as f:
29
+ for chunk in res.iter_content(chunk_size=8192):
30
+ f.write(chunk)
31
+ print(f"[+] Downloaded {filename}")
32
+ return filename
33
+ else:
34
+ print(f"[!] Failed to download {filename}: {res.status_code}")
35
+ return None
36
+ except Exception as e:
37
+ print(f"[!] Error downloading {filename}: {e}")
38
+ return None
39
+
40
+ def upload_to_dataset(filepath):
41
+ try:
42
+ upload_file(
43
+ path_or_fileobj=filepath,
44
+ path_in_repo=f"{DATA_PATH}/{os.path.basename(filepath)}",
45
+ repo_id=REPO_ID,
46
+ repo_type="dataset",
47
+ token=HF_TOKEN
48
+ )
49
+ print(f"[+] Uploaded {filepath}")
50
+ except Exception as e:
51
+ print(f"[!] Upload failed for {filepath}: {e}")
52
+
53
+ if __name__ == "__main__":
54
+ files = get_video_list()
55
+ for file in files:
56
+ local_file = download_video(file)
57
+ if local_file:
58
+ upload_to_dataset(local_file)