Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import gradio as gr
|
|
| 5 |
import pandas as pd
|
| 6 |
import json
|
| 7 |
import tempfile
|
|
|
|
| 8 |
|
| 9 |
from constants import *
|
| 10 |
from huggingface_hub import Repository
|
|
@@ -26,9 +27,14 @@ def add_new_eval(
|
|
| 26 |
if input_file is None:
|
| 27 |
return "Error! Empty file!"
|
| 28 |
|
| 29 |
-
upload_data=json.loads(input_file)
|
|
|
|
| 30 |
submission_repo = Repository(local_dir=SUBMISSION_NAME, clone_from=SUBMISSION_URL, use_auth_token=HF_TOKEN, repo_type="dataset")
|
| 31 |
submission_repo.git_pull()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
shutil.copyfile(CSV_DIR, os.path.join(SUBMISSION_NAME, f"{input_file}"))
|
| 33 |
|
| 34 |
csv_data = pd.read_csv(CSV_DIR)
|
|
@@ -50,13 +56,24 @@ def add_new_eval(
|
|
| 50 |
else:
|
| 51 |
model_name = '[' + model_name + '](' + model_link + ')'
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
# add new data
|
| 54 |
new_data = [
|
| 55 |
model_name
|
| 56 |
]
|
| 57 |
for key in TASK_INFO:
|
| 58 |
if key in upload_data:
|
| 59 |
-
new_data.append(upload_data[key]
|
| 60 |
else:
|
| 61 |
new_data.append(0)
|
| 62 |
csv_data.loc[col] = new_data
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import json
|
| 7 |
import tempfile
|
| 8 |
+
import datetime
|
| 9 |
|
| 10 |
from constants import *
|
| 11 |
from huggingface_hub import Repository
|
|
|
|
| 27 |
if input_file is None:
|
| 28 |
return "Error! Empty file!"
|
| 29 |
|
| 30 |
+
# upload_data=json.loads(input_file)
|
| 31 |
+
upload_content = input_file.read()
|
| 32 |
submission_repo = Repository(local_dir=SUBMISSION_NAME, clone_from=SUBMISSION_URL, use_auth_token=HF_TOKEN, repo_type="dataset")
|
| 33 |
submission_repo.git_pull()
|
| 34 |
+
filename = now.strftime("%Y%m%d_%H%M%S")
|
| 35 |
+
now = datetime.datetime.now()
|
| 36 |
+
with open(f'{filename}.zip','wb') as f:
|
| 37 |
+
f.write(input_file)
|
| 38 |
shutil.copyfile(CSV_DIR, os.path.join(SUBMISSION_NAME, f"{input_file}"))
|
| 39 |
|
| 40 |
csv_data = pd.read_csv(CSV_DIR)
|
|
|
|
| 56 |
else:
|
| 57 |
model_name = '[' + model_name + '](' + model_link + ')'
|
| 58 |
|
| 59 |
+
os.makedirs(filename, exist_ok=True)
|
| 60 |
+
with zipfile.ZipFile(io.BytesIO(input_file.read()), 'r') as zip_ref:
|
| 61 |
+
zip_ref.extractall(filename)
|
| 62 |
+
|
| 63 |
+
upload_data = {}
|
| 64 |
+
for file in os.listdir(filename):
|
| 65 |
+
with open(os.path.join(filename, file)) as ff:
|
| 66 |
+
cur_json = json.load(ff)
|
| 67 |
+
if isinstance(cur_json, dict):
|
| 68 |
+
for key in cur_json:
|
| 69 |
+
upload_data[key] = cur_json[key][0]
|
| 70 |
# add new data
|
| 71 |
new_data = [
|
| 72 |
model_name
|
| 73 |
]
|
| 74 |
for key in TASK_INFO:
|
| 75 |
if key in upload_data:
|
| 76 |
+
new_data.append(upload_data[key])
|
| 77 |
else:
|
| 78 |
new_data.append(0)
|
| 79 |
csv_data.loc[col] = new_data
|