File size: 916 Bytes
52cdd46
5b3bdb7
 
 
 
bc1eba4
5b3bdb7
 
 
 
 
 
 
 
52cdd46
 
 
cf2fec5
 
 
 
52cdd46
 
 
cf2fec5
52cdd46
 
 
 
cf2fec5
5b3bdb7
52cdd46
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
import gradio as gr
from smolagents import CodeAgent, InferenceClientModel
from tools.party_menu import suggest_menu
from tools.party_song import suggest_party_music
from tools.party_time import estimate_preparation_time
from smolagents import FinalAnswerTool

model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-7B-Instruct")

agent = CodeAgent(
    model=model,
    tools=[FinalAnswerTool(), suggest_menu, suggest_party_music, estimate_preparation_time],
)

# 定义 Gradio 接口
def chat_fn(message, history):
    result = agent.run(message)
    if not isinstance(result, str):
        result = str(result)
    return result  # ✅ 只返回助手的回复


demo = gr.ChatInterface(
    fn=chat_fn,
    chatbot=gr.Chatbot(type="messages"),
    textbox=gr.Textbox(placeholder="Ask Alfred to help plan your party..."),
    title="Alfred Party Planner Agent",
)


if __name__ == "__main__":
    demo.launch()