Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
import traceback
|
| 3 |
from typing import Any, Dict, Optional, Tuple, List
|
|
@@ -324,4 +326,47 @@ def run_and_submit_all(profile: Optional[gr.OAuthProfile] = None):
|
|
| 324 |
logs.append({"task_id": task_id, "answer": ans, "question": q})
|
| 325 |
|
| 326 |
if not answers:
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
import re
|
| 4 |
import traceback
|
| 5 |
from typing import Any, Dict, Optional, Tuple, List
|
|
|
|
| 326 |
logs.append({"task_id": task_id, "answer": ans, "question": q})
|
| 327 |
|
| 328 |
if not answers:
|
| 329 |
+
return "⚠️ 全部題目都 SKIPPED,目前沒有可提交答案。", pd.DataFrame(logs)
|
| 330 |
+
|
| 331 |
+
payload = {
|
| 332 |
+
"username": username,
|
| 333 |
+
"agent_code": "basic-agent-wiki-br",
|
| 334 |
+
"answers": answers,
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
r2 = requests.post(f"{api_url}/submit", json=payload, timeout=120, headers={"User-Agent": "Mozilla/5.0"})
|
| 338 |
+
r2.raise_for_status()
|
| 339 |
+
res = r2.json()
|
| 340 |
+
|
| 341 |
+
status = (
|
| 342 |
+
"✅ Submission Successful!\n"
|
| 343 |
+
f"User: {res.get('username')}\n"
|
| 344 |
+
f"Score: {res.get('score')}% "
|
| 345 |
+
f"({res.get('correct_count')}/{res.get('total_attempted')})\n"
|
| 346 |
+
f"Message: {res.get('message')}\n\n"
|
| 347 |
+
f"Local stats -> Submitted: {len(answers)}, Skipped: {skipped}"
|
| 348 |
+
)
|
| 349 |
+
|
| 350 |
+
return status, pd.DataFrame(logs)
|
| 351 |
+
|
| 352 |
+
except Exception as e:
|
| 353 |
+
tb = traceback.format_exc()
|
| 354 |
+
return f"❌ Runtime Error:\n{e}\n\n{tb}", None
|
| 355 |
+
|
| 356 |
+
# =============================
|
| 357 |
+
# UI
|
| 358 |
+
# =============================
|
| 359 |
+
with gr.Blocks() as demo:
|
| 360 |
+
gr.Markdown("# Basic Agent Evaluation Runner (No Paid Model)")
|
| 361 |
+
gr.Markdown("✅ Login → Run → Submit\n\n新增:Malko / 1928 Olympics / 1977 Yankees(純 requests + pandas)")
|
| 362 |
+
|
| 363 |
+
gr.LoginButton()
|
| 364 |
+
run_btn = gr.Button("Run Evaluation & Submit All Answers")
|
| 365 |
+
|
| 366 |
+
status_box = gr.Textbox(label="Run Status / Submission Result", lines=12, interactive=False)
|
| 367 |
+
table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 368 |
+
|
| 369 |
+
run_btn.click(fn=run_and_submit_all, outputs=[status_box, table])
|
| 370 |
+
|
| 371 |
+
if __name__ == "__main__":
|
| 372 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|