File size: 1,225 Bytes
d078b7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# gradio_generator.py - Wraps robot behavior and simulator into Gradio interface

import gradio as gr
from deployer.simulator_interface import VirtualRobot

# The logic that interprets voice or text and maps it to robot actions
def robot_behavior(user_input: str):
    bot = VirtualRobot()
    user_input = user_input.lower().strip()

    if any(greet in user_input for greet in ["hello", "hi", "hey", "welcome"]):
        return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!")
    elif user_input.startswith("say"):
        return bot.perform_action(user_input)
    else:
        return bot.perform_action("say I didn't understand that. Try again!")

# Generate Gradio app dynamically
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
    with gr.Blocks() as demo:
        gr.Markdown(f"""# 🤖 {title}
        {description}
        """)
        with gr.Row():
            inp = gr.Textbox(label="Speak or Type")
            out = gr.Textbox(label="Robot Response")
        btn = gr.Button("Send")
        btn.click(robot_behavior, inputs=inp, outputs=out)
    return demo

# For testing
if __name__ == "__main__":
    app = launch_gradio_app()
    app.launch()