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()