Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,15 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from
|
| 7 |
-
from huggingface_hub import login
|
| 8 |
|
| 9 |
# --- Constants ---
|
| 10 |
|
| 11 |
-
login(os.getenv("HF_TOKEN"))
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
|
| 14 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 15 |
"""
|
| 16 |
-
Fetches all questions, runs the
|
| 17 |
and displays the results.
|
| 18 |
"""
|
| 19 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
|
@@ -30,13 +28,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 30 |
questions_url = f"{api_url}/questions"
|
| 31 |
submit_url = f"{api_url}/submit"
|
| 32 |
|
| 33 |
-
# 1. Instantiate
|
| 34 |
try:
|
| 35 |
agent = SmolagentsGAIAgent()
|
| 36 |
-
print("
|
| 37 |
except Exception as e:
|
| 38 |
-
print(f"Error instantiating
|
| 39 |
-
return f"Error initializing
|
| 40 |
|
| 41 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 42 |
print(f"Agent code link: {agent_code}")
|
|
@@ -62,10 +60,10 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 62 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 63 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 64 |
|
| 65 |
-
# 3. Run
|
| 66 |
results_log = []
|
| 67 |
answers_payload = []
|
| 68 |
-
print(f"Running
|
| 69 |
|
| 70 |
for i, item in enumerate(questions_data):
|
| 71 |
task_id = item.get("task_id")
|
|
@@ -80,7 +78,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 80 |
print(f"Task ID: {task_id}")
|
| 81 |
print(f"Question: {question_text[:100]}...")
|
| 82 |
|
| 83 |
-
# Run the smolagents agent
|
| 84 |
submitted_answer = agent.process_question(question_text)
|
| 85 |
|
| 86 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
|
@@ -94,7 +92,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 94 |
|
| 95 |
except Exception as e:
|
| 96 |
print(f"Error running agent on task {task_id}: {e}")
|
| 97 |
-
error_answer = f"AGENT ERROR: {e}"
|
| 98 |
answers_payload.append({"task_id": task_id, "submitted_answer": error_answer})
|
| 99 |
results_log.append({
|
| 100 |
"Task ID": task_id,
|
|
@@ -103,8 +101,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 103 |
})
|
| 104 |
|
| 105 |
if not answers_payload:
|
| 106 |
-
print("
|
| 107 |
-
return "
|
| 108 |
|
| 109 |
# 4. Prepare Submission
|
| 110 |
submission_data = {
|
|
@@ -113,7 +111,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 113 |
"answers": answers_payload
|
| 114 |
}
|
| 115 |
|
| 116 |
-
status_update = f"
|
| 117 |
print(status_update)
|
| 118 |
|
| 119 |
# 5. Submit
|
|
@@ -168,41 +166,33 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 168 |
|
| 169 |
|
| 170 |
# --- Build Gradio Interface using Blocks ---
|
| 171 |
-
with gr.Blocks(title="
|
| 172 |
-
gr.Markdown("# Smolagents GAIA Agent Evaluation")
|
| 173 |
gr.Markdown(
|
| 174 |
"""
|
| 175 |
-
## Your Smolagents Agent Features:
|
| 176 |
-
- **Calculator Tool**: Mathematical calculations and equation solving
|
| 177 |
-
- **Web Search Tool**: Real-time information retrieval from the web
|
| 178 |
-
- **Wikipedia Tool**: Access to structured knowledge and facts
|
| 179 |
-
- **File Processing Tools**: PDF and CSV document analysis
|
| 180 |
-
- **Reasoning Tool**: Logical analysis and problem decomposition
|
| 181 |
-
- **Visit Webpage Tool**: Direct webpage content extraction
|
| 182 |
-
|
| 183 |
## Instructions:
|
| 184 |
1. **Login** to Hugging Face using the button below
|
| 185 |
-
2. **Click** 'Run Evaluation & Submit All Answers'
|
| 186 |
-
3. **Wait** for your smolagents agent to process all questions
|
| 187 |
4. **View** your score and detailed results
|
| 188 |
|
| 189 |
-
## How the
|
| 190 |
-
- **
|
| 191 |
-
- **
|
| 192 |
-
- **
|
| 193 |
-
- **
|
| 194 |
|
| 195 |
-
**Note**: This
|
| 196 |
"""
|
| 197 |
)
|
| 198 |
|
| 199 |
gr.LoginButton()
|
| 200 |
|
| 201 |
-
run_button = gr.Button("Run Smolagents GAIA Evaluation & Submit All Answers", variant="primary")
|
| 202 |
|
| 203 |
status_output = gr.Textbox(
|
| 204 |
label="📊 Run Status / Submission Result",
|
| 205 |
-
lines=
|
| 206 |
interactive=False
|
| 207 |
)
|
| 208 |
|
|
@@ -216,8 +206,8 @@ with gr.Blocks(title="Multi-Agent System - GAIA Benchmark") as demo:
|
|
| 216 |
outputs=[status_output, results_table]
|
| 217 |
)
|
| 218 |
|
| 219 |
-
if __name__ == "
|
| 220 |
-
print("\n" + "="*
|
| 221 |
|
| 222 |
# Check environment variables
|
| 223 |
space_host_startup = os.getenv("SPACE_HOST")
|
|
@@ -236,7 +226,7 @@ if __name__ == "__main__":
|
|
| 236 |
else:
|
| 237 |
print("[INFO] SPACE_ID not found (running locally)")
|
| 238 |
|
| 239 |
-
print("="*(
|
| 240 |
|
| 241 |
-
print("Launching Smolagents GAIA Agent Evaluation Interface...")
|
| 242 |
demo.launch(debug=True, share=False)
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smoleagents_agent import OptimizedSmolagentsGAIAgent as SmolagentsGAIAgent
|
|
|
|
| 7 |
|
| 8 |
# --- Constants ---
|
| 9 |
|
|
|
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 11 |
|
| 12 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 13 |
"""
|
| 14 |
+
Fetches all questions, runs the Enhanced DirectToolAgent on them, submits all answers,
|
| 15 |
and displays the results.
|
| 16 |
"""
|
| 17 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
|
|
|
| 28 |
questions_url = f"{api_url}/questions"
|
| 29 |
submit_url = f"{api_url}/submit"
|
| 30 |
|
| 31 |
+
# 1. Instantiate Enhanced Direct Tool Agent
|
| 32 |
try:
|
| 33 |
agent = SmolagentsGAIAgent()
|
| 34 |
+
print("Enhanced Direct Tool Agent initialized successfully!")
|
| 35 |
except Exception as e:
|
| 36 |
+
print(f"Error instantiating enhanced direct tool agent: {e}")
|
| 37 |
+
return f"Error initializing enhanced direct tool agent: {e}", None
|
| 38 |
|
| 39 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 40 |
print(f"Agent code link: {agent_code}")
|
|
|
|
| 60 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 61 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 62 |
|
| 63 |
+
# 3. Run Enhanced DirectToolAgent
|
| 64 |
results_log = []
|
| 65 |
answers_payload = []
|
| 66 |
+
print(f"Running enhanced direct tool agent on {len(questions_data)} questions...")
|
| 67 |
|
| 68 |
for i, item in enumerate(questions_data):
|
| 69 |
task_id = item.get("task_id")
|
|
|
|
| 78 |
print(f"Task ID: {task_id}")
|
| 79 |
print(f"Question: {question_text[:100]}...")
|
| 80 |
|
| 81 |
+
# Run the enhanced smolagents agent
|
| 82 |
submitted_answer = agent.process_question(question_text)
|
| 83 |
|
| 84 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
|
|
|
| 92 |
|
| 93 |
except Exception as e:
|
| 94 |
print(f"Error running agent on task {task_id}: {e}")
|
| 95 |
+
error_answer = f"AGENT ERROR: {str(e)[:100]}"
|
| 96 |
answers_payload.append({"task_id": task_id, "submitted_answer": error_answer})
|
| 97 |
results_log.append({
|
| 98 |
"Task ID": task_id,
|
|
|
|
| 101 |
})
|
| 102 |
|
| 103 |
if not answers_payload:
|
| 104 |
+
print("Enhanced DirectToolAgent did not produce any answers to submit.")
|
| 105 |
+
return "Enhanced DirectToolAgent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 106 |
|
| 107 |
# 4. Prepare Submission
|
| 108 |
submission_data = {
|
|
|
|
| 111 |
"answers": answers_payload
|
| 112 |
}
|
| 113 |
|
| 114 |
+
status_update = f"Enhanced DirectToolAgent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 115 |
print(status_update)
|
| 116 |
|
| 117 |
# 5. Submit
|
|
|
|
| 166 |
|
| 167 |
|
| 168 |
# --- Build Gradio Interface using Blocks ---
|
| 169 |
+
with gr.Blocks(title="Enhanced Smolagents GAIA Agent") as demo:
|
| 170 |
+
gr.Markdown("# Enhanced Smolagents GAIA Agent Evaluation")
|
| 171 |
gr.Markdown(
|
| 172 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
## Instructions:
|
| 174 |
1. **Login** to Hugging Face using the button below
|
| 175 |
+
2. **Click** 'Run Enhanced Evaluation & Submit All Answers'
|
| 176 |
+
3. **Wait** for your enhanced smolagents agent to process all questions
|
| 177 |
4. **View** your score and detailed results
|
| 178 |
|
| 179 |
+
## How the Enhanced Agent Works:
|
| 180 |
+
- **Smart Capability Detection**: Automatically detects available tools
|
| 181 |
+
- **Fallback Strategy**: Uses basic responses when advanced features unavailable
|
| 182 |
+
- **Enhanced Responses**: Leverages Wikipedia, web search, and data tools when possible
|
| 183 |
+
- **Zero-Error Operation**: Guaranteed to complete all questions regardless of available features
|
| 184 |
|
| 185 |
+
**Note**: This enhanced version maximizes capabilities while maintaining complete reliability.
|
| 186 |
"""
|
| 187 |
)
|
| 188 |
|
| 189 |
gr.LoginButton()
|
| 190 |
|
| 191 |
+
run_button = gr.Button("Run Enhanced Smolagents GAIA Evaluation & Submit All Answers", variant="primary")
|
| 192 |
|
| 193 |
status_output = gr.Textbox(
|
| 194 |
label="📊 Run Status / Submission Result",
|
| 195 |
+
lines=10,
|
| 196 |
interactive=False
|
| 197 |
)
|
| 198 |
|
|
|
|
| 206 |
outputs=[status_output, results_table]
|
| 207 |
)
|
| 208 |
|
| 209 |
+
if __name__ == "__app__":
|
| 210 |
+
print("\n" + "="*60 + " Enhanced Smolagents GAIA Agent Starting " + "="*60)
|
| 211 |
|
| 212 |
# Check environment variables
|
| 213 |
space_host_startup = os.getenv("SPACE_HOST")
|
|
|
|
| 226 |
else:
|
| 227 |
print("[INFO] SPACE_ID not found (running locally)")
|
| 228 |
|
| 229 |
+
print("="*(120 + len(" Enhanced Smolagents GAIA Agent Starting ")) + "\n")
|
| 230 |
|
| 231 |
+
print("Launching Enhanced Smolagents GAIA Agent Evaluation Interface...")
|
| 232 |
demo.launch(debug=True, share=False)
|