Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,34 +3,27 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
# -------------------------
|
| 7 |
-
# Constants
|
| 8 |
-
# -------------------------
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# -------------------------
|
| 12 |
-
# Basic Agent
|
| 13 |
# -------------------------
|
| 14 |
class BasicAgent:
|
| 15 |
-
"""Your GAIA Agent logic can go here."""
|
| 16 |
def __init__(self):
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
|
| 19 |
def __call__(self, question: str) -> str:
|
| 20 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 21 |
-
# TODO: Replace with real
|
| 22 |
-
fixed_answer = "This is a default answer."
|
| 23 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 24 |
-
return fixed_answer
|
| 25 |
|
| 26 |
# -------------------------
|
| 27 |
# Run & Submit Function
|
| 28 |
# -------------------------
|
| 29 |
-
def run_and_submit_all(profile:
|
| 30 |
-
if profile
|
| 31 |
return "❌ Please login with your Hugging Face account.", None
|
| 32 |
|
| 33 |
-
username = profile.username
|
| 34 |
print(f"Logged in as: {username}")
|
| 35 |
|
| 36 |
space_id = os.getenv("SPACE_ID", "unknown-space")
|
|
@@ -96,14 +89,11 @@ with gr.Blocks() as demo:
|
|
| 96 |
)
|
| 97 |
|
| 98 |
user_state = gr.State()
|
| 99 |
-
login_btn = gr.LoginButton()
|
| 100 |
run_btn = gr.Button("🚀 Run Evaluation & Submit All Answers")
|
| 101 |
status_box = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
| 102 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 103 |
|
| 104 |
-
# Login event stores profile in user_state
|
| 105 |
-
login_btn.login(lambda profile: profile, outputs=user_state)
|
| 106 |
-
|
| 107 |
# Run button uses user_state as profile
|
| 108 |
run_btn.click(run_and_submit_all, inputs=user_state, outputs=[status_box, results_table])
|
| 109 |
|
|
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 7 |
|
| 8 |
# -------------------------
|
| 9 |
+
# Basic GAIA Agent
|
| 10 |
# -------------------------
|
| 11 |
class BasicAgent:
|
|
|
|
| 12 |
def __init__(self):
|
| 13 |
print("BasicAgent initialized.")
|
| 14 |
|
| 15 |
def __call__(self, question: str) -> str:
|
| 16 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 17 |
+
return "This is a default answer." # TODO: Replace with real logic
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# -------------------------
|
| 20 |
# Run & Submit Function
|
| 21 |
# -------------------------
|
| 22 |
+
def run_and_submit_all(profile: dict | None):
|
| 23 |
+
if not profile:
|
| 24 |
return "❌ Please login with your Hugging Face account.", None
|
| 25 |
|
| 26 |
+
username = profile.get("username", "unknown_user")
|
| 27 |
print(f"Logged in as: {username}")
|
| 28 |
|
| 29 |
space_id = os.getenv("SPACE_ID", "unknown-space")
|
|
|
|
| 89 |
)
|
| 90 |
|
| 91 |
user_state = gr.State()
|
| 92 |
+
login_btn = gr.LoginButton(outputs=user_state) # <-- 這裡直接綁定 gr.State
|
| 93 |
run_btn = gr.Button("🚀 Run Evaluation & Submit All Answers")
|
| 94 |
status_box = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
| 95 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
# Run button uses user_state as profile
|
| 98 |
run_btn.click(run_and_submit_all, inputs=user_state, outputs=[status_box, results_table])
|
| 99 |
|