Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,57 @@
|
|
1 |
-
# app.py - Unified RoboSage Deployer &
|
|
|
2 |
import os
|
|
|
|
|
3 |
from core_creator.voice_to_app import VoiceToAppCreator
|
4 |
from deployer.simulator_interface import VirtualRobot
|
5 |
-
import gradio as gr
|
6 |
-
import asyncio
|
7 |
|
8 |
-
# Pipeline runner: generates app blueprint and code
|
9 |
async def run_pipeline(idea: str) -> str:
|
10 |
-
"""
|
11 |
-
Runs the voice-to-app pipeline and returns a status message.
|
12 |
-
"""
|
13 |
creator = VoiceToAppCreator(idea)
|
14 |
assets = creator.run_pipeline()
|
15 |
title = assets.get("blueprint", {}).get("title", "<unknown>")
|
16 |
return f"✅ Generated app: {title}"
|
17 |
|
18 |
-
# Synchronous wrapper for Gradio use
|
19 |
def deploy_callback(idea: str) -> str:
|
|
|
20 |
return asyncio.run(run_pipeline(idea))
|
21 |
|
22 |
-
# Robot simulator callback
|
23 |
def robot_behavior(user_input: str) -> str:
|
24 |
-
"""
|
25 |
-
Simulate robot action based on user text.
|
26 |
-
"""
|
27 |
return VirtualRobot().perform_action(user_input)
|
28 |
|
29 |
# Build unified Gradio interface
|
30 |
with gr.Blocks() as demo:
|
31 |
-
gr.Markdown("
|
32 |
-
|
33 |
with gr.Column():
|
34 |
gr.Markdown("## 1️⃣ Generate App")
|
35 |
-
user_idea = gr.Textbox(
|
|
|
|
|
|
|
36 |
deploy_btn = gr.Button("Generate App", key="deploy-app-btn")
|
37 |
deploy_status = gr.Textbox(label="Status")
|
38 |
-
deploy_btn.click(
|
|
|
|
|
|
|
|
|
39 |
|
40 |
with gr.Column():
|
41 |
gr.Markdown("## 2️⃣ Robot Simulator")
|
42 |
-
robot_input = gr.Textbox(
|
|
|
|
|
|
|
43 |
robot_btn = gr.Button("Send", key="simulate-btn")
|
44 |
robot_output = gr.Textbox(label="Robot Response", lines=4)
|
45 |
-
robot_btn.click(
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
# Launch the complete app
|
48 |
if __name__ == "__main__":
|
49 |
demo.launch()
|
|
|
1 |
+
# app.py - Unified RoboSage Deployer & Simulator (CPU & Spaces-compatible)
|
2 |
+
|
3 |
import os
|
4 |
+
import asyncio
|
5 |
+
import gradio as gr
|
6 |
from core_creator.voice_to_app import VoiceToAppCreator
|
7 |
from deployer.simulator_interface import VirtualRobot
|
|
|
|
|
8 |
|
|
|
9 |
async def run_pipeline(idea: str) -> str:
|
10 |
+
"""Runs voice-to-app pipeline and returns a status message."""
|
|
|
|
|
11 |
creator = VoiceToAppCreator(idea)
|
12 |
assets = creator.run_pipeline()
|
13 |
title = assets.get("blueprint", {}).get("title", "<unknown>")
|
14 |
return f"✅ Generated app: {title}"
|
15 |
|
|
|
16 |
def deploy_callback(idea: str) -> str:
|
17 |
+
"""Sync wrapper for Gradio."""
|
18 |
return asyncio.run(run_pipeline(idea))
|
19 |
|
|
|
20 |
def robot_behavior(user_input: str) -> str:
|
21 |
+
"""Simulate robot action based on user text."""
|
|
|
|
|
22 |
return VirtualRobot().perform_action(user_input)
|
23 |
|
24 |
# Build unified Gradio interface
|
25 |
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("# 🚀 RoboSage\nGenerate your custom robot app and test it live.")
|
27 |
+
|
28 |
with gr.Column():
|
29 |
gr.Markdown("## 1️⃣ Generate App")
|
30 |
+
user_idea = gr.Textbox(
|
31 |
+
label="Your Robot Idea",
|
32 |
+
placeholder="e.g. A friendly greeting robot."
|
33 |
+
)
|
34 |
deploy_btn = gr.Button("Generate App", key="deploy-app-btn")
|
35 |
deploy_status = gr.Textbox(label="Status")
|
36 |
+
deploy_btn.click(
|
37 |
+
fn=deploy_callback,
|
38 |
+
inputs=[user_idea],
|
39 |
+
outputs=[deploy_status]
|
40 |
+
)
|
41 |
|
42 |
with gr.Column():
|
43 |
gr.Markdown("## 2️⃣ Robot Simulator")
|
44 |
+
robot_input = gr.Textbox(
|
45 |
+
label="Speak or Type Command",
|
46 |
+
placeholder="hello or say You rock!"
|
47 |
+
)
|
48 |
robot_btn = gr.Button("Send", key="simulate-btn")
|
49 |
robot_output = gr.Textbox(label="Robot Response", lines=4)
|
50 |
+
robot_btn.click(
|
51 |
+
fn=robot_behavior,
|
52 |
+
inputs=[robot_input],
|
53 |
+
outputs=[robot_output]
|
54 |
+
)
|
55 |
|
|
|
56 |
if __name__ == "__main__":
|
57 |
demo.launch()
|