Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -50,6 +50,8 @@ def generate_metadata(video_name, title, description, uploader, file_location, t
|
|
50 |
|
51 |
def update_index_file(new_metadata_path):
|
52 |
index_file_path = "metadata/index-video.json"
|
|
|
|
|
53 |
|
54 |
try:
|
55 |
# Try to download existing index file
|
@@ -58,21 +60,26 @@ def update_index_file(new_metadata_path):
|
|
58 |
repo_type="space",
|
59 |
path_in_repo=index_file_path
|
60 |
)
|
61 |
-
|
62 |
-
|
63 |
-
# If file
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Create temporary file for updated index
|
71 |
-
|
72 |
-
os.makedirs(os.path.dirname(temp_index_path), exist_ok=True)
|
73 |
-
|
74 |
with open(temp_index_path, "w") as f:
|
75 |
-
|
76 |
|
77 |
# Upload updated index file
|
78 |
api.upload_file(
|
@@ -83,7 +90,8 @@ def update_index_file(new_metadata_path):
|
|
83 |
)
|
84 |
|
85 |
# Clean up temporary file
|
86 |
-
os.
|
|
|
87 |
|
88 |
def upload_video_to_hf(video_file, original_video_name, title, description, uploader, custom_thumbnail=None):
|
89 |
# Create temp paths
|
|
|
50 |
|
51 |
def update_index_file(new_metadata_path):
|
52 |
index_file_path = "metadata/index-video.json"
|
53 |
+
temp_dir = "temp"
|
54 |
+
temp_index_path = os.path.join(temp_dir, "temp_index.json")
|
55 |
|
56 |
try:
|
57 |
# Try to download existing index file
|
|
|
60 |
repo_type="space",
|
61 |
path_in_repo=index_file_path
|
62 |
)
|
63 |
+
current_paths = existing_content.decode().strip()
|
64 |
+
|
65 |
+
# If the file exists but is empty, initialize it
|
66 |
+
if not current_paths:
|
67 |
+
updated_paths = new_metadata_path
|
68 |
+
else:
|
69 |
+
# Split existing paths and add the new one
|
70 |
+
paths_list = current_paths.split(';')
|
71 |
+
if new_metadata_path not in paths_list:
|
72 |
+
paths_list.append(new_metadata_path)
|
73 |
+
updated_paths = ';'.join(paths_list)
|
74 |
+
|
75 |
+
except Exception as e:
|
76 |
+
# If file doesn't exist or can't be loaded, start with just the new path
|
77 |
+
updated_paths = new_metadata_path
|
78 |
|
79 |
# Create temporary file for updated index
|
80 |
+
os.makedirs(temp_dir, exist_ok=True)
|
|
|
|
|
81 |
with open(temp_index_path, "w") as f:
|
82 |
+
f.write(updated_paths)
|
83 |
|
84 |
# Upload updated index file
|
85 |
api.upload_file(
|
|
|
90 |
)
|
91 |
|
92 |
# Clean up temporary file
|
93 |
+
if os.path.exists(temp_index_path):
|
94 |
+
os.remove(temp_index_path)
|
95 |
|
96 |
def upload_video_to_hf(video_file, original_video_name, title, description, uploader, custom_thumbnail=None):
|
97 |
# Create temp paths
|