Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -76,20 +76,31 @@ def update_index_file(new_metadata_path):
|
|
76 |
json_files = glob.glob(os.path.join(metadata_dir, '*-index.json'))
|
77 |
|
78 |
base_url = "huggingface.co/spaces/vericudebuget/ok4231/raw/main/metadata/"
|
79 |
-
paths = [
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
new_metadata_filename = os.path.basename(new_metadata_path)
|
82 |
new_full_path = f"{base_url}{new_metadata_filename}"
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
-
|
|
|
87 |
|
88 |
index_path = os.path.join(temp_dir, 'metadata', 'video-index.json')
|
89 |
os.makedirs(os.path.dirname(index_path), exist_ok=True)
|
90 |
with open(index_path, 'w') as f:
|
91 |
f.write(index_content)
|
92 |
|
|
|
93 |
hf_api.upload_file(
|
94 |
path_or_fileobj=index_path,
|
95 |
path_in_repo="metadata/video-index.json",
|
|
|
76 |
json_files = glob.glob(os.path.join(metadata_dir, '*-index.json'))
|
77 |
|
78 |
base_url = "huggingface.co/spaces/vericudebuget/ok4231/raw/main/metadata/"
|
79 |
+
paths = []
|
80 |
|
81 |
+
for f in json_files:
|
82 |
+
file_timestamp = datetime.now().isoformat() # Get the current timestamp
|
83 |
+
file_path = f"{base_url}{os.path.basename(f)}"
|
84 |
+
paths.append({"url": file_path, "timestamp": file_timestamp})
|
85 |
+
|
86 |
+
# Add the new metadata file with the current timestamp
|
87 |
new_metadata_filename = os.path.basename(new_metadata_path)
|
88 |
new_full_path = f"{base_url}{new_metadata_filename}"
|
89 |
+
file_timestamp = datetime.now().isoformat() # Get timestamp for the new metadata file
|
90 |
+
|
91 |
+
# Check if the new file is already in the list, if not, add it
|
92 |
+
if not any(entry['url'] == new_full_path for entry in paths):
|
93 |
+
paths.append({"url": new_full_path, "timestamp": file_timestamp})
|
94 |
|
95 |
+
# Convert the paths list to a proper JSON format
|
96 |
+
index_content = json.dumps(paths, indent=2)
|
97 |
|
98 |
index_path = os.path.join(temp_dir, 'metadata', 'video-index.json')
|
99 |
os.makedirs(os.path.dirname(index_path), exist_ok=True)
|
100 |
with open(index_path, 'w') as f:
|
101 |
f.write(index_content)
|
102 |
|
103 |
+
# Upload the updated index file
|
104 |
hf_api.upload_file(
|
105 |
path_or_fileobj=index_path,
|
106 |
path_in_repo="metadata/video-index.json",
|