Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool,
|
| 2 |
import datetime
|
| 3 |
import pytz
|
| 4 |
import yaml
|
|
@@ -6,70 +6,38 @@ from tools.final_answer import FinalAnswerTool
|
|
| 6 |
from Gradio_UI import GradioUI
|
| 7 |
|
| 8 |
|
| 9 |
-
# Example of a creative custom tool
|
| 10 |
-
@tool
|
| 11 |
-
def random_welcome_message(name: str) -> str:
|
| 12 |
-
"""Greet a user with a random, cheerful message.
|
| 13 |
-
Args:
|
| 14 |
-
name: The name of the user to greet.
|
| 15 |
-
"""
|
| 16 |
-
import random
|
| 17 |
-
messages = [
|
| 18 |
-
f"Hey {name}, hope your day’s fantastic!",
|
| 19 |
-
f"Welcome aboard, {name}! Ready to explore?",
|
| 20 |
-
f"Good to see you, {name}! Let's create some magic!"
|
| 21 |
-
]
|
| 22 |
-
return random.choice(messages)
|
| 23 |
-
|
| 24 |
-
|
| 25 |
@tool
|
| 26 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 27 |
-
"""
|
| 28 |
-
Args:
|
| 29 |
-
timezone: Example: 'Asia/Kolkata' or 'America/New_York'
|
| 30 |
-
"""
|
| 31 |
try:
|
| 32 |
tz = pytz.timezone(timezone)
|
| 33 |
-
|
| 34 |
-
return f"The current local time in {timezone} is: {
|
| 35 |
except Exception as e:
|
| 36 |
-
return f"Error
|
| 37 |
|
| 38 |
|
| 39 |
-
# Initialize the tools
|
| 40 |
final_answer = FinalAnswerTool()
|
| 41 |
search_tool = DuckDuckGoSearchTool()
|
| 42 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
model =
|
| 46 |
max_tokens=2048,
|
| 47 |
temperature=0.7,
|
| 48 |
-
model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 49 |
)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
prompt_templates = yaml.safe_load(stream)
|
| 54 |
|
| 55 |
-
# Build the multi-tool agent
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[
|
| 59 |
-
final_answer,
|
| 60 |
-
search_tool,
|
| 61 |
-
image_generation_tool,
|
| 62 |
-
get_current_time_in_timezone,
|
| 63 |
-
random_welcome_message
|
| 64 |
-
],
|
| 65 |
max_steps=6,
|
| 66 |
verbosity_level=1,
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
name="WebSearchAssistant",
|
| 70 |
-
description="Multi-modal assistant with search, chatbot, and image generation",
|
| 71 |
-
prompt_templates=prompt_templates
|
| 72 |
)
|
| 73 |
|
| 74 |
-
# Launch an interactive Gradio UI
|
| 75 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import pytz
|
| 4 |
import yaml
|
|
|
|
| 6 |
from Gradio_UI import GradioUI
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@tool
|
| 10 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 11 |
+
"""Return the current time in the specified timezone."""
|
|
|
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
tz = pytz.timezone(timezone)
|
| 14 |
+
time_now = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 15 |
+
return f"The current local time in {timezone} is: {time_now}"
|
| 16 |
except Exception as e:
|
| 17 |
+
return f"Error: {e}"
|
| 18 |
|
| 19 |
|
|
|
|
| 20 |
final_answer = FinalAnswerTool()
|
| 21 |
search_tool = DuckDuckGoSearchTool()
|
| 22 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 23 |
|
| 24 |
+
# Replaced InferenceClientModel → HfApiModel
|
| 25 |
+
model = HfApiModel(
|
| 26 |
max_tokens=2048,
|
| 27 |
temperature=0.7,
|
| 28 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
with open("prompts.yaml", "r") as f:
|
| 32 |
+
prompt_templates = yaml.safe_load(f)
|
|
|
|
| 33 |
|
|
|
|
| 34 |
agent = CodeAgent(
|
| 35 |
model=model,
|
| 36 |
+
tools=[final_answer, search_tool, image_generation_tool, get_current_time_in_timezone],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
max_steps=6,
|
| 38 |
verbosity_level=1,
|
| 39 |
+
description="A multi-tool web chatbot and image generator",
|
| 40 |
+
prompt_templates=prompt_templates,
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
|
|
|
| 43 |
GradioUI(agent).launch()
|