|
import gradio as gr |
|
from deployer.simulator_interface import VirtualRobot |
|
|
|
def robot_behavior(user_input: str): |
|
"""Handle robot interaction logic""" |
|
bot = VirtualRobot() |
|
text = user_input.lower().strip() |
|
|
|
if any(g in text for g in ["hello", "hi", "hey", "welcome"]): |
|
return bot.perform_action("wave") + "\n" + bot.perform_action("say Hello there!") |
|
if text.startswith("say"): |
|
return bot.perform_action(text) |
|
return bot.perform_action("say I didn't understand that. Try again!") |
|
|
|
def create_interface(): |
|
"""Create the Gradio interface components""" |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# π€ RoboSage App\n\nYour robot, your voice.") |
|
|
|
with gr.Row(): |
|
input_text = gr.Textbox(label="Speak or Type", lines=1) |
|
send_button = gr.Button("Send", variant="primary") |
|
|
|
output_text = gr.Textbox(label="Robot Response", interactive=False) |
|
|
|
|
|
send_button.click( |
|
fn=robot_behavior, |
|
inputs=input_text, |
|
outputs=output_text |
|
) |
|
|
|
input_text.submit( |
|
fn=robot_behavior, |
|
inputs=input_text, |
|
outputs=output_text |
|
) |
|
|
|
return demo |
|
|
|
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."): |
|
"""Launch the Gradio application""" |
|
interface = create_interface() |
|
return interface |
|
|
|
if __name__ == "__main__": |
|
app = launch_gradio_app() |
|
app.launch( |
|
server_name="0.0.0.0", |
|
server_port=7860, |
|
share=False |
|
) |