File size: 1,219 Bytes
a1fe5a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()