Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from generator import generate_app, enhance_app
|
| 4 |
+
from helpers import save_as_zip
|
| 5 |
+
|
| 6 |
+
def run_app(user_input, enhance_prompt, action, state):
|
| 7 |
+
if not state:
|
| 8 |
+
code_bundle = generate_app(user_input)
|
| 9 |
+
state = {"bundle": code_bundle, "history": []}
|
| 10 |
+
else:
|
| 11 |
+
code_bundle = state["bundle"]
|
| 12 |
+
|
| 13 |
+
if action == "Enhance" and enhance_prompt:
|
| 14 |
+
enhanced = enhance_app(code_bundle, enhance_prompt)
|
| 15 |
+
state["bundle"] = enhanced
|
| 16 |
+
state["history"].append(enhance_prompt)
|
| 17 |
+
code_bundle = enhanced
|
| 18 |
+
|
| 19 |
+
zip_bytes = save_as_zip(code_bundle)
|
| 20 |
+
return code_bundle["full_code"], zip_bytes, state
|
| 21 |
+
|
| 22 |
+
with gr.Blocks(title="Auto App Builder") as iface:
|
| 23 |
+
gr.Markdown("# 🛠️ Auto App Builder (Gemini‑Powered)")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
inp = gr.Textbox(label="App idea / Prompt", lines=2, placeholder="e.g. inventory management system")
|
| 26 |
+
btn = gr.Button("Generate")
|
| 27 |
+
code_out = gr.Code(label="Generated Code", language="bash")
|
| 28 |
+
enh = gr.Textbox(label="Enhancement Prompt", lines=1, placeholder="Add login, PDF export, etc.")
|
| 29 |
+
btn_enh = gr.Button("Enhance")
|
| 30 |
+
zip_dl = gr.Download(label="Download ZIP")
|
| 31 |
+
state = gr.State()
|
| 32 |
+
btn.click(run_app, [inp, enh, gr.State(""), state], [code_out, zip_dl, state])
|
| 33 |
+
btn_enh.click(run_app, [inp, enh, gr.State("Enhance"), state], [code_out, zip_dl, state])
|
| 34 |
+
|
| 35 |
+
iface.launch(auth=True)
|