Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -12,12 +14,22 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
print("
|
|
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
print(f"
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
@@ -163,7 +175,6 @@ with gr.Blocks() as demo:
|
|
163 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
164 |
|
165 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
166 |
-
# Removed max_rows=10 from DataFrame constructor
|
167 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
168 |
|
169 |
run_button.click(
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagent import CodeAgent
|
7 |
+
from smolagent.tools.python import PythonInterpreterTool
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
|
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
class BasicAgent:
|
16 |
def __init__(self):
|
17 |
+
print("🔧 Inicializando CodeAgent com ferramenta Python.")
|
18 |
+
tools = [PythonInterpreterTool()]
|
19 |
+
self.agent = CodeAgent(tools=tools)
|
20 |
+
|
21 |
def __call__(self, question: str) -> str:
|
22 |
+
print(f"🤖 Pergunta recebida: {question[:100]}")
|
23 |
+
response = self.agent.run(question)
|
24 |
+
|
25 |
+
# Extrair apenas a resposta final (sem o raciocínio completo)
|
26 |
+
if "FINAL ANSWER:" in response:
|
27 |
+
answer = response.split("FINAL ANSWER:")[-1].strip()
|
28 |
+
else:
|
29 |
+
answer = response.strip()
|
30 |
+
|
31 |
+
print(f"✅ Resposta final: {answer}")
|
32 |
+
return answer
|
33 |
|
34 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
35 |
"""
|
|
|
175 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
176 |
|
177 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
|
|
178 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
179 |
|
180 |
run_button.click(
|