Spaces:
Sleeping
Sleeping
File size: 1,260 Bytes
5b2a93d b3034f4 fe06bc9 b3034f4 0aee8a7 b3034f4 fe06bc9 b3034f4 9b5b26a b3034f4 8c01ffb b3034f4 5b2a93d b3034f4 5b2a93d 0aee8a7 b3034f4 cc64db5 b3034f4 8c01ffb 8fe992b b3034f4 0aee8a7 b3034f4 5b2a93d b3034f4 5b2a93d 8fe992b 5b2a93d dc5b413 b3034f4 | 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 | from smolagents import CodeAgent, InferenceClientModel, tool
import gradio as gr
# ----------------------
# TOOL
# ----------------------
@tool
def my_custom_tool(arg1: str) -> str:
"""
A simple tool that echoes user input.
Args:
arg1 (str): The text input provided by the user.
Returns:
str: The same text prefixed with 'Echo:'.
"""
return f"Echo: {arg1}"
# ----------------------
# MODEL (FIXED PROPERLY)
# ----------------------
model = InferenceClientModel(
model_id="HuggingFaceH4/zephyr-7b-beta",
temperature=0.2
)
# ----------------------
# AGENT
# ----------------------
agent = CodeAgent(
model=model,
tools=[my_custom_tool]
)
# ----------------------
# FUNCTION
# ----------------------
def run_agent(user_input):
try:
return str(agent.run(user_input))
except Exception as e:
return f"Error: {str(e)}"
# ----------------------
# UI
# ----------------------
demo = gr.Interface(
fn=run_agent,
inputs=gr.Textbox(lines=5, placeholder="Ask something..."),
outputs=gr.Textbox(),
title="SmolAgents Demo",
description="Working agent with tool"
)
# ----------------------
# LAUNCH
# ----------------------
if __name__ == "__main__":
demo.launch() |