Spaces:
Runtime error
Runtime error
File size: 3,264 Bytes
a97f7e8 aefee5e f3fdf8e 88fb741 f3fdf8e 9198ee4 6c9c15c f3fdf8e 9198ee4 4c5e86f a97f7e8 5e77b3a f3fdf8e 81e4fe9 f3fdf8e 88fb741 81e4fe9 f3fdf8e d636e38 81e4fe9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 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()
|