Spaces:
Runtime error
Runtime error
Commit ·
2045c7a
1
Parent(s): 211b63f
First iteratiion of gradio fixing
Browse files- app.py +64 -61
- src/leaderboard/build_leaderboard.py +4 -4
app.py
CHANGED
|
@@ -82,65 +82,68 @@ def build_demo():
|
|
| 82 |
gr.Markdown("# ✨ Submit your model here!", elem_classes="markdown-text")
|
| 83 |
|
| 84 |
with gr.Column():
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
return False
|
| 99 |
-
|
| 100 |
-
submit_info = {
|
| 101 |
-
"model_name": model_name,
|
| 102 |
-
"username": username,
|
| 103 |
-
"file_name": file_name,
|
| 104 |
-
"link": link if link else "",
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
current_info.append(submit_info)
|
| 108 |
-
|
| 109 |
-
with open(f"{DATA_PATH}/{SUBMITS_META_FILE}", "w", encoding="utf-8") as submit_meta_file:
|
| 110 |
-
submit_meta_file.write(json.dumps(current_info))
|
| 111 |
-
|
| 112 |
-
logging.info(
|
| 113 |
-
"New submition: file from %s saved to %s with model %s",
|
| 114 |
-
username,
|
| 115 |
-
file_name,
|
| 116 |
-
model_name,
|
| 117 |
-
)
|
| 118 |
-
API.upload_file(
|
| 119 |
-
path_or_fileobj=file.name,
|
| 120 |
-
path_in_repo="arena-hard-v0.1/model_answers/" + file_name,
|
| 121 |
-
repo_id=METAINFO_DATASET,
|
| 122 |
-
repo_type="dataset",
|
| 123 |
-
token=HF_TOKEN_PRIVATE,
|
| 124 |
-
)
|
| 125 |
-
API.upload_file(
|
| 126 |
-
path_or_fileobj=SUBMITS_META_FILE,
|
| 127 |
-
path_in_repo=SUBMITS_META_FILE,
|
| 128 |
-
repo_id=METAINFO_DATASET,
|
| 129 |
-
repo_type="dataset",
|
| 130 |
-
token=HF_TOKEN_PRIVATE,
|
| 131 |
-
)
|
| 132 |
-
change_judgement(1)
|
| 133 |
-
return file.name
|
| 134 |
-
|
| 135 |
-
if model_name_textbox and submitter_username:
|
| 136 |
-
file_output = gr.File()
|
| 137 |
-
upload_button = gr.UploadButton(
|
| 138 |
-
"Click to Upload & Submit Answers", file_types=["*"], file_count="single"
|
| 139 |
-
)
|
| 140 |
-
upload_button.upload(upload_file, inputs=[upload_button, model_name_textbox, submitter_username, model_link_web], outputs= file_output)
|
| 141 |
-
|
| 142 |
return demo
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# print(os.system('cd src/gen && ../../.venv/bin/python gen_judgment.py'))
|
| 146 |
# print(os.system('cd src/gen/ && python show_result.py --output'))
|
|
@@ -159,8 +162,8 @@ def update_board():
|
|
| 159 |
|
| 160 |
|
| 161 |
def change_judgement(need_recalc_state=0):
|
| 162 |
-
with open(PERSISTENT_FILE_CHECK_PATH, "w", encoding="utf-8") as
|
| 163 |
-
|
| 164 |
API.upload_file(
|
| 165 |
path_or_fileobj=PERSISTENT_FILE_CHECK_PATH,
|
| 166 |
path_in_repo=PERSISTENT_FILE_CHECK,
|
|
@@ -176,8 +179,8 @@ if __name__ == "__main__":
|
|
| 176 |
|
| 177 |
need_recalc = False
|
| 178 |
try:
|
| 179 |
-
with open(PERSISTENT_FILE_CHECK_PATH, "r", encoding="utf-8") as
|
| 180 |
-
need_recalc =
|
| 181 |
except FileNotFoundError:
|
| 182 |
need_recalc = True
|
| 183 |
|
|
|
|
| 82 |
gr.Markdown("# ✨ Submit your model here!", elem_classes="markdown-text")
|
| 83 |
|
| 84 |
with gr.Column():
|
| 85 |
+
file_input = gr.File(label="Upload File")
|
| 86 |
+
model_name_input = gr.Textbox(label="Model name")
|
| 87 |
+
username_input = gr.Textbox(label="Username") # can we get this info from hf??
|
| 88 |
+
link_input = gr.Textbox(label="Link to Model") # can we get this info from hf??
|
| 89 |
+
|
| 90 |
+
submit_button = gr.Button("Submit")
|
| 91 |
+
output=gr.Textbox(label="Output")
|
| 92 |
+
|
| 93 |
+
submit_button.click(
|
| 94 |
+
fn=upload_file,
|
| 95 |
+
inputs=[file_input, model_name_input, username_input, link_input],
|
| 96 |
+
output=output,
|
| 97 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
return demo
|
| 99 |
|
| 100 |
+
def upload_file(file, model_name, username, link):
|
| 101 |
+
if not file or not model_name or not username:
|
| 102 |
+
return "Fields file, model_name and username are required"
|
| 103 |
+
|
| 104 |
+
file_name = file.name.split("/")[-1] if "/" in file.name else file.name
|
| 105 |
+
file_name = model_name.value + "_" + file_name
|
| 106 |
+
|
| 107 |
+
with open(f"{DATA_PATH}/{SUBMITS_META_FILE}", "r", encoding="utf-8") as submit_meta_file:
|
| 108 |
+
current_info = json.loads(submit_meta_file)
|
| 109 |
+
|
| 110 |
+
# for now just do not save same name model
|
| 111 |
+
if any(filter(lambda x: x["model_name"] == model_name, current_info)):
|
| 112 |
+
return False
|
| 113 |
+
|
| 114 |
+
submit_info = {
|
| 115 |
+
"model_name": model_name,
|
| 116 |
+
"username": username,
|
| 117 |
+
"file_name": file_name,
|
| 118 |
+
"link": link if link else "",
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
current_info.append(submit_info)
|
| 122 |
+
|
| 123 |
+
with open(f"{DATA_PATH}/{SUBMITS_META_FILE}", "w", encoding="utf-8") as submit_meta_file:
|
| 124 |
+
submit_meta_file.write(json.dumps(current_info))
|
| 125 |
+
logging.info(
|
| 126 |
+
"New submition: file from %s saved to %s with model %s",
|
| 127 |
+
username,
|
| 128 |
+
file_name,
|
| 129 |
+
model_name,
|
| 130 |
+
)
|
| 131 |
+
API.upload_file(
|
| 132 |
+
path_or_fileobj=file.name,
|
| 133 |
+
path_in_repo="arena-hard-v0.1/model_answers/" + file_name,
|
| 134 |
+
repo_id=METAINFO_DATASET,
|
| 135 |
+
repo_type="dataset",
|
| 136 |
+
token=HF_TOKEN_PRIVATE,
|
| 137 |
+
)
|
| 138 |
+
API.upload_file(
|
| 139 |
+
path_or_fileobj=SUBMITS_META_FILE,
|
| 140 |
+
path_in_repo=SUBMITS_META_FILE,
|
| 141 |
+
repo_id=METAINFO_DATASET,
|
| 142 |
+
repo_type="dataset",
|
| 143 |
+
token=HF_TOKEN_PRIVATE,
|
| 144 |
+
)
|
| 145 |
+
change_judgement(1)
|
| 146 |
+
return file.name
|
| 147 |
|
| 148 |
# print(os.system('cd src/gen && ../../.venv/bin/python gen_judgment.py'))
|
| 149 |
# print(os.system('cd src/gen/ && python show_result.py --output'))
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
def change_judgement(need_recalc_state=0):
|
| 165 |
+
with open(PERSISTENT_FILE_CHECK_PATH, "w", encoding="utf-8") as pers_file:
|
| 166 |
+
pers_file.write(str(need_recalc_state))
|
| 167 |
API.upload_file(
|
| 168 |
path_or_fileobj=PERSISTENT_FILE_CHECK_PATH,
|
| 169 |
path_in_repo=PERSISTENT_FILE_CHECK,
|
|
|
|
| 179 |
|
| 180 |
need_recalc = False
|
| 181 |
try:
|
| 182 |
+
with open(PERSISTENT_FILE_CHECK_PATH, "r", encoding="utf-8") as pers_file:
|
| 183 |
+
need_recalc = pers_file.read() == "1"
|
| 184 |
except FileNotFoundError:
|
| 185 |
need_recalc = True
|
| 186 |
|
src/leaderboard/build_leaderboard.py
CHANGED
|
@@ -66,7 +66,7 @@ def build_leadearboard_df():
|
|
| 66 |
submit_info = pd.DataFrame.from_records(
|
| 67 |
json.load(submit_meta_file), columns=["model_name", "username", "file_name", "link"]
|
| 68 |
)[["model_name", "username", "file_name", "link"]]
|
| 69 |
-
|
| 70 |
# get the format of file_name that is used by the judge
|
| 71 |
# can be hijacked using dot character
|
| 72 |
# but i am not going to work just for that case
|
|
@@ -76,12 +76,12 @@ def build_leadearboard_df():
|
|
| 76 |
|
| 77 |
# Merge the DataFrames
|
| 78 |
merged_df = pd.merge(battle_info, submit_info, how="left", left_on="model", right_on="file_name")
|
| 79 |
-
|
| 80 |
# Fill missing usernames with None
|
| 81 |
merged_df["username"] = merged_df["username"].fillna("")
|
| 82 |
merged_df.loc[merged_df['model_name'].isna(), 'model_name'] = merged_df['model']
|
| 83 |
-
|
| 84 |
# Drop the model_name column if no longer needed
|
| 85 |
-
merged_df = merged_df.drop(columns=["file_name", "model"])
|
| 86 |
|
| 87 |
return merged_df.copy()
|
|
|
|
| 66 |
submit_info = pd.DataFrame.from_records(
|
| 67 |
json.load(submit_meta_file), columns=["model_name", "username", "file_name", "link"]
|
| 68 |
)[["model_name", "username", "file_name", "link"]]
|
| 69 |
+
|
| 70 |
# get the format of file_name that is used by the judge
|
| 71 |
# can be hijacked using dot character
|
| 72 |
# but i am not going to work just for that case
|
|
|
|
| 76 |
|
| 77 |
# Merge the DataFrames
|
| 78 |
merged_df = pd.merge(battle_info, submit_info, how="left", left_on="model", right_on="file_name")
|
| 79 |
+
|
| 80 |
# Fill missing usernames with None
|
| 81 |
merged_df["username"] = merged_df["username"].fillna("")
|
| 82 |
merged_df.loc[merged_df['model_name'].isna(), 'model_name'] = merged_df['model']
|
| 83 |
+
|
| 84 |
# Drop the model_name column if no longer needed
|
| 85 |
+
merged_df = merged_df.drop(columns=["file_name", "model"])[["model_name", "lower", "score", "upper", "username", "link"]]
|
| 86 |
|
| 87 |
return merged_df.copy()
|