Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,30 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
@@ -40,7 +56,19 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 40 |
|
| 41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 42 |
try:
|
| 43 |
-
agent =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Error instantiating agent: {e}")
|
| 46 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, WikipediaTool, load_tool, TransformersModel
|
| 14 |
+
|
| 15 |
+
# 1. Load a powerful model (32B+)
|
| 16 |
+
model = TransformersModel(
|
| 17 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", # Swap for Mixtral 8x22B, DBRX, etc.
|
| 18 |
+
device_map="auto",
|
| 19 |
+
max_new_tokens=2048,
|
| 20 |
+
trust_remote_code=True
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
search_tool = DuckDuckGoSearchTool() # Web search
|
| 24 |
+
wikipedia_tool = WikipediaTool() # Wikipedia search
|
| 25 |
+
|
| 26 |
+
# Calculator (from Hugging Face Hub)
|
| 27 |
+
calculator_tool = load_tool("smol-ai/calculator", trust_remote_code=True)
|
| 28 |
+
|
| 29 |
+
# Summarizer (from Hugging Face Hub)
|
| 30 |
+
summarizer_tool = load_tool("smol-ai/summarizer", trust_remote_code=True)
|
| 31 |
+
|
| 32 |
+
# Unit converter (from Hugging Face Hub)
|
| 33 |
+
unit_converter_tool = load_tool("smol-ai/unit-converter", trust_remote_code=True)
|
| 34 |
+
|
| 35 |
+
# Date/time tool (from Hugging Face Hub)
|
| 36 |
+
datetime_tool = load_tool("smol-ai/datetime", trust_remote_code=True)
|
| 37 |
|
| 38 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 39 |
"""
|
|
|
|
| 56 |
|
| 57 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 58 |
try:
|
| 59 |
+
agent = CodeAgent(
|
| 60 |
+
tools=[
|
| 61 |
+
search_tool,
|
| 62 |
+
wikipedia_tool,
|
| 63 |
+
calculator_tool,
|
| 64 |
+
summarizer_tool,
|
| 65 |
+
unit_converter_tool,
|
| 66 |
+
datetime_tool
|
| 67 |
+
],
|
| 68 |
+
model=model,
|
| 69 |
+
add_base_tools=True # Adds Python REPL, file I/O, etc.
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
except Exception as e:
|
| 73 |
print(f"Error instantiating agent: {e}")
|
| 74 |
return f"Error initializing agent: {e}", None
|