robosage / deployer /gradio_generator.py
mgbam's picture
Update deployer/gradio_generator.py
19487ce verified
raw
history blame
1.15 kB
import gradio as gr
from deployer.simulator_interface import VirtualRobot
# Robot behavior logic
def robot_behavior(user_input: str):
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!")
# Build Gradio app with proper Blocks context
def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."):
with gr.Blocks() as demo:
gr.Markdown(f"# πŸ€– {title}\n\n{description}")
# Define components (no trailing commas!)
inp = gr.Textbox(label="Speak or Type", lines=1)
out = gr.Textbox(label="Robot Response")
btn = gr.Button("Send", key="send-btn")
# Wire event inside the same Blocks context
btn.click(fn=robot_behavior, inputs=[inp], outputs=[out])
return demo
# For local testing
if __name__ == "__main__":
app = launch_gradio_app()
app.launch()