Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import yaml | |
| from agent_builder import build_agent | |
| Load prompts | |
| with open("prompts.yaml", "r") as f: | |
| templates = yaml.safe_load(f) | |
| agent = build_agent(config_path="agent.json", prompts=templates) | |
| def run_agent(user_input, timezone, target_lang, image_desc): | |
| # Build tool inputs | |
| conv = [] | |
| if user_input: | |
| conv.append(user_input) | |
| # select tool by input pattern | |
| if target_lang: | |
| out = agent.run_tool("translate_text", text=user_input, lang=target_lang) | |
| elif timezone: | |
| out = agent.run_tool("get_current_time_in_timezone", timezone=timezone) | |
| elif image_desc: | |
| out = agent.run_tool("text_to_image", description=image_desc) | |
| else: | |
| out = agent.run(user_input) | |
| return out | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## First Agent Template - Updated") | |
| user_input = gr.Textbox(label="Ask something:") | |
| timezone = gr.Textbox(label="Timezone for time tool (e.g. Europe/Rome)", value="Europe/Rome") | |
| target_lang = gr.Textbox(label="Target language for translation tool (e.g. it, en)") | |
| image_desc = gr.Textbox(label="Description for image generation") | |
| output = gr.Textbox(label="Output") | |
| btn = gr.Button("Run") | |
| btn.click(run_agent, inputs=[user_input, timezone, target_lang, image_desc], outputs=[output]) | |
| demo.launch() |