Spaces:
Sleeping
Sleeping
cousintiz commited on
Commit ·
bcde1a4
1
Parent(s): 62492c8
abc
Browse files
app.py
CHANGED
|
@@ -38,23 +38,43 @@ class SmolGaiaAgent:
|
|
| 38 |
api_key=os.getenv("HF_TOKEN"),
|
| 39 |
)
|
| 40 |
|
| 41 |
-
# 2) CodeAgent with system_prompt
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
def __call__(self, question: str) -> str:
|
| 53 |
"""
|
| 54 |
Runs the CodeAgent on one question and returns the final answer string.
|
| 55 |
"""
|
| 56 |
print(f"[SmolGaiaAgent] Question: {question[:80]}...")
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
answer = str(answer).strip()
|
| 59 |
print(f"[SmolGaiaAgent] Answer: {answer}")
|
| 60 |
return answer
|
|
@@ -89,6 +109,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 89 |
agent = SmolGaiaAgent()
|
| 90 |
except Exception as e:
|
| 91 |
print(f"Error instantiating agent: {e}")
|
|
|
|
|
|
|
| 92 |
return f"Error initializing agent: {e}", None
|
| 93 |
|
| 94 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
@@ -131,6 +153,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 131 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 132 |
except Exception as e:
|
| 133 |
print(f"Error running agent on task {task_id}: {e}")
|
|
|
|
|
|
|
| 134 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 135 |
|
| 136 |
if not answers_payload:
|
|
@@ -204,7 +228,6 @@ with gr.Blocks() as demo:
|
|
| 204 |
"""
|
| 205 |
)
|
| 206 |
|
| 207 |
-
# Store the login button to access its value
|
| 208 |
login_button = gr.LoginButton()
|
| 209 |
|
| 210 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
|
@@ -212,8 +235,6 @@ with gr.Blocks() as demo:
|
|
| 212 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
| 213 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 214 |
|
| 215 |
-
# The key is to NOT specify inputs - Gradio will automatically inject the profile
|
| 216 |
-
# when the function signature includes the profile parameter
|
| 217 |
run_button.click(
|
| 218 |
fn=run_and_submit_all,
|
| 219 |
outputs=[status_output, results_table]
|
|
|
|
| 38 |
api_key=os.getenv("HF_TOKEN"),
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# 2) CodeAgent - try with system_prompt, fallback without if it fails
|
| 42 |
+
try:
|
| 43 |
+
self.agent = CodeAgent(
|
| 44 |
+
tools=[],
|
| 45 |
+
add_base_tools=True,
|
| 46 |
+
model=self.model,
|
| 47 |
+
max_steps=8,
|
| 48 |
+
system_prompt=GAIA_SYSTEM_PROMPT,
|
| 49 |
+
)
|
| 50 |
+
print("Agent initialized with system_prompt parameter")
|
| 51 |
+
except TypeError as e:
|
| 52 |
+
# If system_prompt is not supported, initialize without it
|
| 53 |
+
print(f"system_prompt not supported in this version, initializing without it: {e}")
|
| 54 |
+
self.agent = CodeAgent(
|
| 55 |
+
tools=[],
|
| 56 |
+
add_base_tools=True,
|
| 57 |
+
model=self.model,
|
| 58 |
+
max_steps=8,
|
| 59 |
+
)
|
| 60 |
+
# We'll prepend the system prompt to each task instead
|
| 61 |
+
self.use_task_prefix = True
|
| 62 |
+
else:
|
| 63 |
+
self.use_task_prefix = False
|
| 64 |
|
| 65 |
def __call__(self, question: str) -> str:
|
| 66 |
"""
|
| 67 |
Runs the CodeAgent on one question and returns the final answer string.
|
| 68 |
"""
|
| 69 |
print(f"[SmolGaiaAgent] Question: {question[:80]}...")
|
| 70 |
+
|
| 71 |
+
# If system_prompt wasn't supported during init, prepend it to the task
|
| 72 |
+
if hasattr(self, 'use_task_prefix') and self.use_task_prefix:
|
| 73 |
+
task = f"{GAIA_SYSTEM_PROMPT}\n\nTask: {question}"
|
| 74 |
+
else:
|
| 75 |
+
task = question
|
| 76 |
+
|
| 77 |
+
answer = self.agent.run(task)
|
| 78 |
answer = str(answer).strip()
|
| 79 |
print(f"[SmolGaiaAgent] Answer: {answer}")
|
| 80 |
return answer
|
|
|
|
| 109 |
agent = SmolGaiaAgent()
|
| 110 |
except Exception as e:
|
| 111 |
print(f"Error instantiating agent: {e}")
|
| 112 |
+
import traceback
|
| 113 |
+
traceback.print_exc()
|
| 114 |
return f"Error initializing agent: {e}", None
|
| 115 |
|
| 116 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
|
|
| 153 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 154 |
except Exception as e:
|
| 155 |
print(f"Error running agent on task {task_id}: {e}")
|
| 156 |
+
import traceback
|
| 157 |
+
traceback.print_exc()
|
| 158 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 159 |
|
| 160 |
if not answers_payload:
|
|
|
|
| 228 |
"""
|
| 229 |
)
|
| 230 |
|
|
|
|
| 231 |
login_button = gr.LoginButton()
|
| 232 |
|
| 233 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
|
|
|
| 235 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
| 236 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 237 |
|
|
|
|
|
|
|
| 238 |
run_button.click(
|
| 239 |
fn=run_and_submit_all,
|
| 240 |
outputs=[status_output, results_table]
|