Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +49 -39
deployer/gradio_generator.py
CHANGED
|
@@ -1,43 +1,53 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
from core_creator.app_blueprint import build_app_code
|
| 8 |
-
from core_creator.voice_to_app import robot_action
|
| 9 |
-
|
| 10 |
-
async def deploy_callback(idea: str):
|
| 11 |
"""
|
| 12 |
-
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Build code files
|
| 20 |
-
os.makedirs(app_dir, exist_ok=False)
|
| 21 |
-
build_app_code(idea, app_dir)
|
| 22 |
-
except Exception as e:
|
| 23 |
-
return f"β Failed to generate app directory for: {idea}", None
|
| 24 |
-
|
| 25 |
-
# Create zip
|
| 26 |
-
zip_path = os.path.join(tmpdir, f"robosage_{safe_name}.zip")
|
| 27 |
-
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 28 |
-
for root, _, files in os.walk(app_dir):
|
| 29 |
-
for file in files:
|
| 30 |
-
full = os.path.join(root, file)
|
| 31 |
-
arc = os.path.relpath(full, app_dir)
|
| 32 |
-
zf.write(full, arc)
|
| 33 |
-
|
| 34 |
-
return f"β
Generated app: {idea}", zip_path
|
| 35 |
-
|
| 36 |
-
def robot_behavior(command: str):
|
| 37 |
"""
|
| 38 |
-
|
| 39 |
"""
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# gradio_generator.py - Gradio interface for voice-to-robot app generation
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from core_creator.voice_to_app import VoiceToAppCreator
|
| 5 |
+
|
| 6 |
+
def deploy_callback(voice_input: str) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
+
Processes the user's voice input to generate a robot app package.
|
| 9 |
"""
|
| 10 |
+
creator = VoiceToAppCreator(voice_input)
|
| 11 |
+
app_package = creator.run_pipeline()
|
| 12 |
+
return app_package
|
| 13 |
+
|
| 14 |
+
def robot_behavior(voice_input: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
+
Generates a summary of the robot's behavior based on the voice input.
|
| 17 |
"""
|
| 18 |
+
creator = VoiceToAppCreator(voice_input)
|
| 19 |
+
app_package = creator.run_pipeline()
|
| 20 |
+
return app_package["blueprint"].get("description", "No description available.")
|
| 21 |
+
|
| 22 |
+
# Gradio Interface
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("# π€ Voice-to-Robot App Generator")
|
| 25 |
+
gr.Markdown("Describe your robot idea, and we'll generate an app blueprint for you.")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
voice_input = gr.Textbox(label="π£οΈ Your Robot Idea", placeholder="e.g., A robot that helps with home cleaning tasks.")
|
| 29 |
+
submit_btn = gr.Button("Generate App")
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
intent_output = gr.Textbox(label="π Detected Intent")
|
| 33 |
+
description_output = gr.Textbox(label="π App Description")
|
| 34 |
+
code_output = gr.Code(label="π» Generated Code", language="python")
|
| 35 |
+
assets_output = gr.JSON(label="π¨ Visual/Audio Assets")
|
| 36 |
+
|
| 37 |
+
def process_input(user_input):
|
| 38 |
+
app_package = deploy_callback(user_input)
|
| 39 |
+
return (
|
| 40 |
+
app_package.get("intent", ""),
|
| 41 |
+
app_package["blueprint"].get("description", ""),
|
| 42 |
+
app_package.get("code", ""),
|
| 43 |
+
app_package.get("assets", {})
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
submit_btn.click(
|
| 47 |
+
fn=process_input,
|
| 48 |
+
inputs=voice_input,
|
| 49 |
+
outputs=[intent_output, description_output, code_output, assets_output]
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
demo.launch()
|