Spaces:
Restarting
on
CPU Upgrade
Restarting
on
CPU Upgrade
hanhainebula
commited on
Commit
•
d306dfd
1
Parent(s):
cf2d912
Calculate md5 in the frontend
Browse files- src/utils.py +16 -2
src/utils.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import json
|
|
|
2 |
from datetime import datetime, timezone
|
3 |
from pathlib import Path
|
4 |
from typing import List
|
@@ -196,6 +197,19 @@ def get_iso_format_timestamp():
|
|
196 |
return iso_format_timestamp, filename_friendly_timestamp
|
197 |
|
198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
def submit_results(filepath: str, model: str, model_url: str, reranker: str, reranker_url: str, version: str = "AIR-Bench_24.04", is_anonymous=False):
|
200 |
if not filepath.endswith(".zip"):
|
201 |
return styled_error(f"file uploading aborted. wrong file type: {filepath}")
|
@@ -221,9 +235,9 @@ def submit_results(filepath: str, model: str, model_url: str, reranker: str, rer
|
|
221 |
|
222 |
# rename the uploaded file
|
223 |
input_fp = Path(filepath)
|
224 |
-
revision =
|
225 |
timestamp_config, timestamp_fn = get_iso_format_timestamp()
|
226 |
-
output_fn = f"{timestamp_fn}-{
|
227 |
input_folder_path = input_fp.parent
|
228 |
|
229 |
if not reranker:
|
|
|
1 |
import json
|
2 |
+
import hashlib
|
3 |
from datetime import datetime, timezone
|
4 |
from pathlib import Path
|
5 |
from typing import List
|
|
|
197 |
return iso_format_timestamp, filename_friendly_timestamp
|
198 |
|
199 |
|
200 |
+
def calculate_file_md5(file_path):
|
201 |
+
md5 = hashlib.md5()
|
202 |
+
|
203 |
+
with open(file_path, 'rb') as f:
|
204 |
+
while True:
|
205 |
+
data = f.read(4096)
|
206 |
+
if not data:
|
207 |
+
break
|
208 |
+
md5.update(data)
|
209 |
+
|
210 |
+
return md5.hexdigest()
|
211 |
+
|
212 |
+
|
213 |
def submit_results(filepath: str, model: str, model_url: str, reranker: str, reranker_url: str, version: str = "AIR-Bench_24.04", is_anonymous=False):
|
214 |
if not filepath.endswith(".zip"):
|
215 |
return styled_error(f"file uploading aborted. wrong file type: {filepath}")
|
|
|
235 |
|
236 |
# rename the uploaded file
|
237 |
input_fp = Path(filepath)
|
238 |
+
revision = calculate_file_md5(filepath)
|
239 |
timestamp_config, timestamp_fn = get_iso_format_timestamp()
|
240 |
+
output_fn = f"{timestamp_fn}-{revision}.zip"
|
241 |
input_folder_path = input_fp.parent
|
242 |
|
243 |
if not reranker:
|