Update deployer/gradio_generator.py
Browse files- deployer/gradio_generator.py +57 -57
deployer/gradio_generator.py
CHANGED
|
@@ -1,97 +1,97 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
from core_creator.voice_to_app import VoiceToAppCreator
|
| 5 |
from deployer.simulator_interface import VirtualRobot
|
|
|
|
| 6 |
|
| 7 |
-
|
| 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 |
-
|
| 19 |
"""
|
| 20 |
-
|
|
|
|
| 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 |
-
|
| 28 |
"""
|
| 29 |
-
|
| 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 |
-
|
| 48 |
"""
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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=
|
| 75 |
-
inputs=[
|
| 76 |
-
outputs=
|
| 77 |
)
|
| 78 |
|
| 79 |
-
|
| 80 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
cmd_input = gr.Textbox(
|
| 82 |
-
label="Command",
|
| 83 |
placeholder="hello or say You rock!"
|
| 84 |
)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
fn=robot_behavior,
|
| 89 |
-
inputs=cmd_input,
|
| 90 |
-
outputs=
|
| 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()
|