Download deployer/gradio_generator.py from mgbam/robosage: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/mgbam/robosage/resolve/134db298d7093c63915c8fbfdc2b852d40eb121f/deployer/gradio_generator.py
- Command line
-
hf download hf://spaces/mgbam/robosage@134db298d7093c63915c8fbfdc2b852d40eb121f/deployer/gradio_generator.py
-
curl -L -o gradio_generator.py https://huggingface.co/spaces/mgbam/robosage/resolve/134db298d7093c63915c8fbfdc2b852d40eb121f/deployer/gradio_generator.py
1.14 kB
| import gradio as gr | |
| from deployer.simulator_interface import VirtualRobot | |
| # Robot behavior logic | |
| 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!") | |
| # Build Gradio app (correct order) | |
| def launch_gradio_app(title="RoboSage App", description="Your robot, your voice."): | |
| with gr.Blocks() as demo: | |
| gr.Markdown(f"# 🤖 {title}\n{description}") | |
| inp = gr.Textbox(label="Speak or Type", lines=1) | |
| out = gr.Textbox(label="Robot Response") | |
| btn = gr.Button("Send") | |
| # 🔧 Must be called after all are inside the Blocks layout | |
| btn.click(fn=robot_behavior, inputs=inp, outputs=out) | |
| return demo | |
| # For local testing | |
| if __name__ == "__main__": | |
| app = launch_gradio_app() | |
| app.launch() | |