mgbam commited on
Commit
1d0d679
Β·
verified Β·
1 Parent(s): 51dfad8

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +22 -55
deployer/gradio_generator.py CHANGED
@@ -1,75 +1,42 @@
1
- ### deployer/gradio_generator.py
2
  import os
3
  import shutil
4
- tempfile
5
  from core_creator.voice_to_app import VoiceToAppCreator
6
  from deployer.simulator_interface import VirtualRobot
7
 
8
  def deploy_callback(idea: str):
9
  """
10
- Generate robot app from idea and package into a ZIP.
11
- Returns (status_message, zip_path)
12
  """
13
  try:
 
14
  creator = VoiceToAppCreator(idea)
15
  assets = creator.run_pipeline()
16
- title = assets.get("blueprint", {}).get("title", "<unknown>")
 
17
  app_dir = assets.get("app_dir")
 
 
18
  if not app_dir or not os.path.isdir(app_dir):
19
- return f"❌ Failed to generate app: {idea}", None
20
- # Create temporary directory for zip
21
- tmpdir = tempfile.mkdtemp()
22
- zip_base = os.path.join(tmpdir, "app")
23
- zip_path = shutil.make_archive(zip_base, 'zip', app_dir)
24
- return f"βœ… Generated app: {title}", zip_path
25
- except Exception as e:
26
- return f"❌ Error: {str(e)}", None
27
 
 
 
 
 
28
 
29
- def robot_behavior(command: str) -> str:
30
- """
31
- Simulate robot behavior based on input command.
32
- """
33
- try:
34
- return VirtualRobot().perform_action(command)
35
- except Exception as e:
36
- return f"❌ Simulator error: {str(e)}"
37
 
 
38
 
39
- ### app.py
40
- import os
41
- import gradio as gr
42
- from deployer.gradio_generator import deploy_callback, robot_behavior
43
 
44
- def generate_app(idea: str):
45
  """
46
- Gradio interface callback to generate app and return status and ZIP file.
47
  """
48
- status, zip_path = deploy_callback(idea)
49
- return status, zip_path
50
-
51
- # Build Gradio UI
52
- with gr.Blocks(css="""
53
- .gradio-container { max-width: 900px; margin: auto; }
54
- .section { padding: 1rem; }
55
- """) as demo:
56
- gr.Markdown("# πŸš€ RoboSage\nGenerate your custom robot app, download it, then test it live.")
57
-
58
- with gr.Column():
59
- gr.Markdown("## 1️⃣ Generate & Download App")
60
- idea_input = gr.Textbox(label="Your Robot Idea", placeholder="e.g. A friendly greeting robot.", lines=2)
61
- gen_btn = gr.Button("Generate App & ZIP")
62
- status_out = gr.Textbox(label="Status", interactive=False)
63
- zip_out = gr.File(label="Download App ZIP")
64
- gen_btn.click(fn=generate_app, inputs=[idea_input], outputs=[status_out, zip_out])
65
-
66
- with gr.Column():
67
- gr.Markdown("## 2️⃣ Robot Simulator")
68
- cmd_input = gr.Textbox(label="Command", placeholder="say 'hello' or 'You rock!'")
69
- sim_btn = gr.Button("Send Command")
70
- sim_out = gr.Textbox(label="Robot Response", interactive=False)
71
- sim_btn.click(fn=robot_behavior, inputs=[cmd_input], outputs=[sim_out])
72
-
73
-
74
- if __name__ == "__main__":
75
- demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), share=False)
 
 
1
  import os
2
  import shutil
3
+ import tempfile
4
  from core_creator.voice_to_app import VoiceToAppCreator
5
  from deployer.simulator_interface import VirtualRobot
6
 
7
  def deploy_callback(idea: str):
8
  """
9
+ Generates the robot app for the given idea, zips it, and returns
10
+ (status_message, path_to_zip_file or None).
11
  """
12
  try:
13
+ # Run your pipeline
14
  creator = VoiceToAppCreator(idea)
15
  assets = creator.run_pipeline()
16
+
17
+ # Extract output directory & title
18
  app_dir = assets.get("app_dir")
19
+ title = assets.get("blueprint", {}).get("title", "<unknown>")
20
+
21
  if not app_dir or not os.path.isdir(app_dir):
22
+ return f"❌ Failed to generate app directory for: {idea}", None
 
 
 
 
 
 
 
23
 
24
+ # Create a temp ZIP file (will persist until process exits)
25
+ tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".zip")
26
+ tmp_path = tmp.name
27
+ tmp.close()
28
 
29
+ # Make archive: shutil wants base name without extension
30
+ base = tmp_path[:-4]
31
+ shutil.make_archive(base, 'zip', root_dir=app_dir)
 
 
 
 
 
32
 
33
+ return f"βœ… Generated app: {title}", tmp_path
34
 
35
+ except Exception as e:
36
+ return f"❌ Error generating app: {e}", None
 
 
37
 
38
+ def robot_behavior(user_input: str) -> str:
39
  """
40
+ Simulate robot behavior.
41
  """
42
+ return VirtualRobot().perform_action(user_input)