Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,18 +10,28 @@ 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 |
-
from smolagents import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# 1. Load a powerful model (32B+)
|
| 16 |
model = TransformersModel(
|
| 17 |
-
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", #
|
| 18 |
device_map="auto",
|
| 19 |
-
max_new_tokens=2048,
|
| 20 |
trust_remote_code=True
|
| 21 |
)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Calculator (from Hugging Face Hub)
|
| 27 |
calculator_tool = load_tool("smol-ai/calculator", trust_remote_code=True)
|
|
@@ -34,7 +44,7 @@ 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 |
"""
|
| 40 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
@@ -56,18 +66,22 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 56 |
|
| 57 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 58 |
try:
|
| 59 |
-
|
| 60 |
-
|
| 61 |
search_tool,
|
| 62 |
-
|
|
|
|
| 63 |
calculator_tool,
|
| 64 |
summarizer_tool,
|
| 65 |
unit_converter_tool,
|
| 66 |
-
datetime_tool
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
print(f"Error instantiating agent: {e}")
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from smolagents import (
|
| 14 |
+
CodeAgent,
|
| 15 |
+
FinalAnswerTool,
|
| 16 |
+
DuckDuckGoSearchTool,
|
| 17 |
+
GoogleSearchTool,
|
| 18 |
+
PythonInterpreterTool,
|
| 19 |
+
load_tool,
|
| 20 |
+
TransformersModel,
|
| 21 |
+
ToolCollection
|
| 22 |
+
)
|
| 23 |
|
| 24 |
# 1. Load a powerful model (32B+)
|
| 25 |
model = TransformersModel(
|
| 26 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", # Or Mixtral 8x22B, DBRX, etc.
|
| 27 |
device_map="auto",
|
|
|
|
| 28 |
trust_remote_code=True
|
| 29 |
)
|
| 30 |
|
| 31 |
+
final_answer_tool = FinalAnswerTool()
|
| 32 |
+
search_tool = DuckDuckGoSearchTool()
|
| 33 |
+
google_tool = GoogleSearchTool()
|
| 34 |
+
python_tool = PythonInterpreterTool()
|
| 35 |
|
| 36 |
# Calculator (from Hugging Face Hub)
|
| 37 |
calculator_tool = load_tool("smol-ai/calculator", trust_remote_code=True)
|
|
|
|
| 44 |
|
| 45 |
# Date/time tool (from Hugging Face Hub)
|
| 46 |
datetime_tool = load_tool("smol-ai/datetime", trust_remote_code=True)
|
| 47 |
+
image_tool_collection = ToolCollection.from_hub("huggingface-tools/diffusion-tools-6630bb19a942c2306a2cdb6f")
|
| 48 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 49 |
"""
|
| 50 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 66 |
|
| 67 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 68 |
try:
|
| 69 |
+
all_tools = [
|
| 70 |
+
final_answer_tool,
|
| 71 |
search_tool,
|
| 72 |
+
google_tool,
|
| 73 |
+
python_tool,
|
| 74 |
calculator_tool,
|
| 75 |
summarizer_tool,
|
| 76 |
unit_converter_tool,
|
| 77 |
+
datetime_tool,
|
| 78 |
+
*image_tool_collection.tools # Add all image tools from the collection
|
| 79 |
+
]
|
| 80 |
+
agent = CodeAgent(
|
| 81 |
+
tools=all_tools,
|
| 82 |
+
model=model,
|
| 83 |
+
add_base_tools=False # Already included above
|
| 84 |
+
)
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
print(f"Error instantiating agent: {e}")
|