Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from agent import BasicAgent
|
| 7 |
|
| 8 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
|
| 10 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 11 |
space_id = os.getenv("SPACE_ID")
|
| 12 |
if profile:
|
| 13 |
-
username= f"{profile.username}"
|
| 14 |
print(f"User logged in: {username}")
|
| 15 |
else:
|
| 16 |
print("User not logged in.")
|
|
@@ -36,11 +36,12 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 36 |
if not questions_data:
|
| 37 |
return "Fetched questions list is empty or invalid format.", None
|
| 38 |
print(f"Fetched {len(questions_data)} questions.")
|
| 39 |
-
except
|
| 40 |
return f"Error fetching questions: {e}", None
|
| 41 |
|
| 42 |
results_log = []
|
| 43 |
answers_payload = []
|
|
|
|
| 44 |
for item in questions_data:
|
| 45 |
task_id = item.get("task_id")
|
| 46 |
question_text = item.get("question")
|
|
@@ -68,14 +69,23 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 68 |
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
| 69 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 70 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 71 |
-
)
|
| 72 |
results_df = pd.DataFrame(results_log)
|
| 73 |
return final_status, results_df
|
| 74 |
-
except
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
|
| 77 |
with gr.Blocks() as demo:
|
| 78 |
-
gr.Markdown("# GAIA Agent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
gr.LoginButton()
|
| 80 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 81 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
|
@@ -84,4 +94,5 @@ with gr.Blocks() as demo:
|
|
| 84 |
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
-
|
|
|
|
|
|
| 1 |
+
from agent import BasicAgent
|
| 2 |
+
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
|
|
|
| 6 |
import pandas as pd
|
|
|
|
| 7 |
|
| 8 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
|
| 10 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 11 |
space_id = os.getenv("SPACE_ID")
|
| 12 |
if profile:
|
| 13 |
+
username = f"{profile.username}"
|
| 14 |
print(f"User logged in: {username}")
|
| 15 |
else:
|
| 16 |
print("User not logged in.")
|
|
|
|
| 36 |
if not questions_data:
|
| 37 |
return "Fetched questions list is empty or invalid format.", None
|
| 38 |
print(f"Fetched {len(questions_data)} questions.")
|
| 39 |
+
except requests.exceptions.RequestException as e:
|
| 40 |
return f"Error fetching questions: {e}", None
|
| 41 |
|
| 42 |
results_log = []
|
| 43 |
answers_payload = []
|
| 44 |
+
print(f"Running agent on {len(questions_data)} questions...")
|
| 45 |
for item in questions_data:
|
| 46 |
task_id = item.get("task_id")
|
| 47 |
question_text = item.get("question")
|
|
|
|
| 69 |
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
| 70 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 71 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 72 |
+
)
|
| 73 |
results_df = pd.DataFrame(results_log)
|
| 74 |
return final_status, results_df
|
| 75 |
+
except requests.exceptions.RequestException as e:
|
| 76 |
+
status_message = f"Submission Failed: {e}"
|
| 77 |
+
results_df = pd.DataFrame(results_log)
|
| 78 |
+
return status_message, results_df
|
| 79 |
|
| 80 |
with gr.Blocks() as demo:
|
| 81 |
+
gr.Markdown("# GAIA Agent Evaluation")
|
| 82 |
+
gr.Markdown("""
|
| 83 |
+
**Instructions:**
|
| 84 |
+
1. Clone this Space and modify the agent logic in `agent.py`.
|
| 85 |
+
2. Log in to Hugging Face below.
|
| 86 |
+
3. Click "Run Evaluation & Submit All Answers" to evaluate.
|
| 87 |
+
""")
|
| 88 |
+
|
| 89 |
gr.LoginButton()
|
| 90 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 91 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
|
|
|
| 94 |
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
+
print("Launching Gradio Interface for Boosted GAIA Agent...")
|
| 98 |
+
demo.launch(debug=True, share=False)
|