mgbam commited on
Commit
1b36f73
Β·
verified Β·
1 Parent(s): 70154bd

Update deployer/gradio_generator.py

Browse files
Files changed (1) hide show
  1. deployer/gradio_generator.py +57 -57
deployer/gradio_generator.py CHANGED
@@ -1,97 +1,97 @@
1
- import os
 
 
2
  import gradio as gr
3
- import openai
4
  from core_creator.voice_to_app import VoiceToAppCreator
5
  from deployer.simulator_interface import VirtualRobot
 
6
 
7
- # Ensure API key is set
8
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
9
- if not OPENAI_API_KEY:
10
- raise EnvironmentError(
11
- "Please set the OPENAI_API_KEY environment variable for audio transcription."
12
- )
13
- openai.api_key = OPENAI_API_KEY
14
-
15
-
16
- def deploy_app(text_input: str) -> str:
17
  """
18
- Generate the app package based on text input.
19
  """
20
- assets = VoiceToAppCreator(text_input).run_pipeline()
 
21
  title = assets.get("blueprint", {}).get("title", "<unknown>")
22
  return f"βœ… Generated app: {title}"
23
 
24
-
25
- def transcribe_audio(audio_path: str) -> str:
26
  """
27
- Transcribe audio file to text using OpenAI Whisper.
28
  """
29
- if not audio_path:
30
- return ""
31
- response = openai.Audio.transcribe(
32
- model="whisper-1",
33
- file=audio_path
34
- )
35
- return response.get("text", "")
36
-
37
 
38
  def robot_behavior(user_input: str) -> str:
39
  """
40
- Simulate robot action based on user command.
41
  """
42
  return VirtualRobot().perform_action(user_input)
43
 
 
 
 
 
 
 
44
 
45
- def launch_gradio_app():
46
  """
47
- Builds and returns the Gradio Blocks UI for the RoboSage app.
48
  """
49
- with gr.Blocks() as demo:
50
- gr.Markdown("# πŸš€ RoboSage\nGenerate your custom robot app and test it live.")
 
 
 
 
51
 
52
  with gr.Row():
53
- with gr.Column():
54
- gr.Markdown("## 1️⃣ Generate App")
55
- text_idea = gr.Textbox(
 
 
 
56
  label="Your Robot Idea",
57
  placeholder="e.g. A friendly greeting robot."
58
  )
59
- audio_idea = gr.Audio(
60
- source="microphone",
61
- type="filepath",
62
- label="Or speak your robot idea"
63
- )
64
  gen_btn = gr.Button("Generate App")
65
- status = gr.Textbox(label="Status")
66
-
67
- # Combine transcription or text input
68
- def on_generate(text, audio):
69
- transcript = transcribe_audio(audio)
70
- final_input = transcript if transcript else text
71
- return deploy_app(final_input)
72
 
73
  gen_btn.click(
74
- fn=on_generate,
75
- inputs=[text_idea, audio_idea],
76
- outputs=status
77
  )
78
 
79
- with gr.Column():
80
- gr.Markdown("## 2️⃣ Robot Simulator")
 
 
 
 
 
 
 
 
 
 
 
81
  cmd_input = gr.Textbox(
82
- label="Command",
83
  placeholder="hello or say You rock!"
84
  )
85
- sim_btn = gr.Button("Send")
86
- resp = gr.Textbox(label="Robot Response", lines=4)
87
- sim_btn.click(
 
88
  fn=robot_behavior,
89
- inputs=cmd_input,
90
- outputs=resp
91
  )
92
 
93
  return demo
94
 
95
-
96
  if __name__ == "__main__":
97
  launch_gradio_app().launch()
 
1
+ # deployer/gradio_generator.py
2
+
3
+ import asyncio
4
  import gradio as gr
5
+
6
  from core_creator.voice_to_app import VoiceToAppCreator
7
  from deployer.simulator_interface import VirtualRobot
8
+ from deployer.revenue_tracker import package_artifacts
9
 
10
+ async def _run_pipeline(idea: str) -> str:
 
 
 
 
 
 
 
 
 
11
  """
12
+ Asynchronously run the voice→app pipeline and return a status message.
13
  """
14
+ creator = VoiceToAppCreator(idea)
15
+ assets = creator.run_pipeline()
16
  title = assets.get("blueprint", {}).get("title", "<unknown>")
17
  return f"βœ… Generated app: {title}"
18
 
19
+ def deploy_callback(idea: str) -> str:
 
20
  """
21
+ Synchronous wrapper for Gradio: generate the app.
22
  """
23
+ return asyncio.run(_run_pipeline(idea))
 
 
 
 
 
 
 
24
 
25
  def robot_behavior(user_input: str) -> str:
26
  """
27
+ Simulate robot action based on a user command.
28
  """
29
  return VirtualRobot().perform_action(user_input)
30
 
31
+ def download_callback() -> str:
32
+ """
33
+ Package all generated app artifacts into a ZIP and return its file path.
34
+ """
35
+ zip_path = package_artifacts()
36
+ return zip_path
37
 
38
+ def launch_gradio_app() -> gr.Blocks:
39
  """
40
+ Build and return the Gradio interface.
41
  """
42
+ demo = gr.Blocks()
43
+ with demo:
44
+ gr.Markdown(
45
+ "## πŸš€ RoboSage \n"
46
+ "Generate your custom robot app and test it live."
47
+ )
48
 
49
  with gr.Row():
50
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
51
+ # 1️⃣ Generate App + Download ZIP
52
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
53
+ with gr.Column(scale=1):
54
+ gr.Markdown("### 1️⃣ Generate App")
55
+ idea_input = gr.Textbox(
56
  label="Your Robot Idea",
57
  placeholder="e.g. A friendly greeting robot."
58
  )
 
 
 
 
 
59
  gen_btn = gr.Button("Generate App")
60
+ status_out = gr.Textbox(label="Status", interactive=False)
 
 
 
 
 
 
61
 
62
  gen_btn.click(
63
+ fn=deploy_callback,
64
+ inputs=[idea_input],
65
+ outputs=[status_out]
66
  )
67
 
68
+ download_btn = gr.Button("πŸ“¦ Download App ZIP")
69
+ zip_out = gr.File(label="Your App ZIP")
70
+
71
+ download_btn.click(
72
+ fn=download_callback,
73
+ outputs=[zip_out]
74
+ )
75
+
76
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
77
+ # 2️⃣ Robot Simulator
78
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
79
+ with gr.Column(scale=1):
80
+ gr.Markdown("### 2️⃣ Robot Simulator")
81
  cmd_input = gr.Textbox(
82
+ label="Speak or Type Command",
83
  placeholder="hello or say You rock!"
84
  )
85
+ send_btn = gr.Button("Send")
86
+ resp_out = gr.Textbox(label="Robot Response", lines=4, interactive=False)
87
+
88
+ send_btn.click(
89
  fn=robot_behavior,
90
+ inputs=[cmd_input],
91
+ outputs=[resp_out]
92
  )
93
 
94
  return demo
95
 
 
96
  if __name__ == "__main__":
97
  launch_gradio_app().launch()