Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants and BasicAgent class as is)
|
| 8 |
# --- Constants ---
|
|
@@ -12,11 +13,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
class BasicAgent:
|
| 13 |
def __init__(self):
|
| 14 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def __call__(self, question: str) -> str:
|
| 16 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 17 |
-
|
| 18 |
-
print(f"Agent returning
|
| 19 |
-
return
|
| 20 |
|
| 21 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 22 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
| 7 |
|
| 8 |
# (Keep Constants and BasicAgent class as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
+
self.agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
|
| 17 |
+
|
| 18 |
+
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and
|
| 19 |
+
finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 20 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated
|
| 21 |
+
list of numbers and/or strings.
|
| 22 |
+
If you are asked for a number, don't use comma to write your number neither use units such as $ or
|
| 23 |
+
percent sign unless specified otherwise.
|
| 24 |
+
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the
|
| 25 |
+
digits in plain text unless specified otherwise.
|
| 26 |
+
If you are asked for a comma separated list, apply the above rules depending of whether the element
|
| 27 |
+
to be put in the list is a number or a string.
|
| 28 |
+
"""
|
| 29 |
+
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
| 30 |
+
|
| 31 |
def __call__(self, question: str) -> str:
|
| 32 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 33 |
+
final_answer = self.agent.run(question)
|
| 34 |
+
print(f"Agent returning final answer: {final_answer}")
|
| 35 |
+
return final_answer
|
| 36 |
|
| 37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 38 |
"""
|