mgbam commited on
Commit
ea3d5fc
Β·
verified Β·
1 Parent(s): aa14814

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +49 -39
deployer/gradio_generator.py CHANGED
@@ -1,43 +1,53 @@
1
- import os
2
- import re
3
- import shutil
4
- import zipfile
5
- import asyncio
6
- import tempfile
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
- Generate the app directory, package into zip, return status and path.
13
  """
14
- # Normalize name
15
- safe_name = re.sub(r"[^a-z0-9]+", "_", idea.lower()).strip("_") or "app"
16
- with tempfile.TemporaryDirectory() as tmpdir:
17
- app_dir = os.path.join(tmpdir, f"robosage_{safe_name}")
18
- try:
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
- Simulate robot behavior: map command to action.
39
  """
40
- try:
41
- return robot_action(command)
42
- except Exception:
43
- return f"❓ Unknown action: {command}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()