Spaces:
Sleeping
Sleeping
File size: 1,360 Bytes
fc8b9a4 de3c494 fc8b9a4 de3c494 fc8b9a4 de3c494 fc8b9a4 de3c494 fc8b9a4 de3c494 fc8b9a4 de3c494 |
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 |
import os
import gradio as gr
from huggingface_hub import login
from smolagents import DuckDuckGoSearchTool, InferenceClientModel, CodeAgent
from tools import best_city, ClassifierTool
web_search_tool = DuckDuckGoSearchTool()
classifier_tool = ClassifierTool()
hf_token = os.environ.get('HF_TOKEN')
if hf_token:
login(token=hf_token)
model = InferenceClientModel(model_id='Qwen/Qwen3-4B-Instruct-2507', token=hf_token)
tools = [
web_search_tool,
classifier_tool,
best_city
]
my_aiagent = CodeAgent(
tools=tools,
# For the purpose of this tutorial, just have tools you integrated.
# Also by default when teh add_base_tools is set to true, it will integrate DuckDuckGo Search.
add_base_tools=False,
model=model
)
def respond(
message,
history: list[dict[str, str]],
system_message
):
full_prompt = f"{system_message}\n\nChat history:\n{history}\n\nUser: {message}"
response = my_aiagent.run(
full_prompt,
max_steps=5,
stream=False,
)
yield response
"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""
chatbot = gr.ChatInterface(
respond,
type="messages",
additional_inputs=[],
)
with gr.Blocks() as demo:
chatbot.render()
if __name__ == "__main__":
demo.launch()
|