DenverJones's picture
Update app.py
a97f7e8 verified
Raw History Blame Contribute Delete
3.26 kB
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
# Define a tool to get motivational quotes (using a simple list for this example)
@tool
def get_motivational_quote() -> str:
"""Returns a motivational quote."""
quotes = [
"Believe you can and you're halfway there.",
"Your limitation—it's only your imagination.",
"The only way to do great work is to love what you do.",
"Strive not to be a success, but rather to be of value.",
"The future belongs to those who believe in the beauty of their dreams."
]
return random.choice(quotes)
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
# Define a tool to get motivational quotes (using a simple list for this example)
@tool
def get_motivational_quote() -> str:
"""Returns a motivational quote."""
quotes = [
"Believe you can and you're halfway there.",
"Your limitation—it's only your imagination.",
"The only way to do great work is to love what you do.",
"Strive not to be a success, but rather to be of value.",
"The future belongs to those who believe in the beauty of their dreams."
]
return random.choice(quotes)
# Initialize the agent with the DeepSeek model
model = HfApiModel(
model_id="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", # Correct model ID
max_tokens=2048, # Adjust as needed
temperature=0.7, # Adjust as needed
)
agent = CodeAgent(tools=[get_motivational_quote], model=model)
def respond(user_input):
quote = agent.run(user_input) # Run the agent with the user input
return quote["final_answer"] if quote and "final_answer" in quote else "No quote available."
with gr.Blocks() as demo:
text_input = gr.Textbox()
text_output = gr.Textbox()
text_input.change(respond, inputs=text_input, outputs=text_output)
final_answer = FinalAnswerTool()
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
custom_role_conversions=None,
)
# Import tool from Hub
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer], # add your tools here (don't remove final_answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch()
dummy_model = DummyModel()
agent = CodeAgent(tools=[get_motivational_quote], model=dummy_model)
def respond(user_input):
quote = agent.run(user_input) # Run the agent with the user input
return quote["final_answer"] # Extract the quote from the agent's response
with gr.Blocks() as demo:
text_input = gr.Textbox()
text_output = gr.Textbox()
text_input.change(respond, inputs=text_input, outputs=text_output)
demo.launch()