Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -174,40 +174,46 @@ def save_csv_to_dataset(df, repo_id, file_name, commit_message):
|
|
| 174 |
if not HF_TOKEN:
|
| 175 |
return "Submit failed: HF_TOKEN secret is missing."
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
|
| 191 |
def save_request_artifact(payload):
|
| 192 |
if not HF_TOKEN:
|
| 193 |
return "Submit failed: HF_TOKEN secret is missing."
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
|
| 213 |
def submit_entry(model_name, split_name, team, contact, model_link, av, at, vt, syncnet, sc, df_arena, nisqa, audiobox, dover, aesthetic, split_selector, sort_selector):
|
|
|
|
| 174 |
if not HF_TOKEN:
|
| 175 |
return "Submit failed: HF_TOKEN secret is missing."
|
| 176 |
|
| 177 |
+
try:
|
| 178 |
+
api = HfApi(token=HF_TOKEN)
|
| 179 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 180 |
+
csv_path = os.path.join(tmpdir, "data.csv")
|
| 181 |
+
df.to_csv(csv_path, index=False)
|
| 182 |
+
api.upload_file(
|
| 183 |
+
path_or_fileobj=csv_path,
|
| 184 |
+
path_in_repo=file_name,
|
| 185 |
+
repo_id=repo_id,
|
| 186 |
+
repo_type="dataset",
|
| 187 |
+
commit_message=commit_message,
|
| 188 |
+
)
|
| 189 |
+
return "ok"
|
| 190 |
+
except Exception as e:
|
| 191 |
+
return f"Submit failed while uploading {repo_id}/{file_name}: {str(e)[:300]}"
|
| 192 |
|
| 193 |
|
| 194 |
def save_request_artifact(payload):
|
| 195 |
if not HF_TOKEN:
|
| 196 |
return "Submit failed: HF_TOKEN secret is missing."
|
| 197 |
|
| 198 |
+
try:
|
| 199 |
+
api = HfApi(token=HF_TOKEN)
|
| 200 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 201 |
+
raw_path = os.path.join(tmpdir, "submission.json")
|
| 202 |
+
with open(raw_path, "w", encoding="utf-8") as f:
|
| 203 |
+
json.dump(payload, f, ensure_ascii=False, indent=2)
|
| 204 |
+
|
| 205 |
+
ts = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
|
| 206 |
+
raw_name = f"submissions/{ts}_{payload['RequestID']}_{payload['Model'].replace(' ', '_')}_{payload['Split']}.json"
|
| 207 |
+
api.upload_file(
|
| 208 |
+
path_or_fileobj=raw_path,
|
| 209 |
+
path_in_repo=raw_name,
|
| 210 |
+
repo_id=REQUEST_REPO,
|
| 211 |
+
repo_type="dataset",
|
| 212 |
+
commit_message=f"New request: {payload['Model']} ({payload['Split']})",
|
| 213 |
+
)
|
| 214 |
+
return "ok"
|
| 215 |
+
except Exception as e:
|
| 216 |
+
return f"Submit failed while saving raw request artifact: {str(e)[:300]}"
|
| 217 |
|
| 218 |
|
| 219 |
def submit_entry(model_name, split_name, team, contact, model_link, av, at, vt, syncnet, sc, df_arena, nisqa, audiobox, dover, aesthetic, split_selector, sort_selector):
|