Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,10 +46,10 @@ def run_app(user_input, enhance_prompt, action, state, progress=gr.Progress()):
|
|
| 46 |
f.write(zip_bytes)
|
| 47 |
|
| 48 |
progress(0.9, desc="Generating preview...")
|
| 49 |
-
preview_html = extract_react_preview(code_bundle
|
| 50 |
|
| 51 |
progress(1.0, desc="Done!")
|
| 52 |
-
return code_bundle
|
| 53 |
|
| 54 |
with gr.Blocks(title="Auto App Builder") as iface:
|
| 55 |
gr.Markdown("# ⚡ Auto App Builder (Gemini Powered)\n_Powered by Google Gemini API_")
|
|
@@ -77,27 +77,35 @@ with gr.Blocks(title="Auto App Builder") as iface:
|
|
| 77 |
def update_file_tree(code, zip_name, preview_path, files, state):
|
| 78 |
if isinstance(files, dict) and len(files) > 0:
|
| 79 |
keys = list(files.keys())
|
| 80 |
-
|
|
|
|
| 81 |
else:
|
| 82 |
return gr.update(choices=[], value=None), ""
|
| 83 |
|
| 84 |
btn.click(
|
| 85 |
fn=run_app,
|
| 86 |
inputs=[inp, enh, gr.State(""), state],
|
| 87 |
-
outputs=[code_out, zip_file, preview, file_selector, state]
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
)
|
|
|
|
| 90 |
btn_enh.click(
|
| 91 |
fn=run_app,
|
| 92 |
inputs=[inp, enh, gr.State("Enhance"), state],
|
| 93 |
-
outputs=[code_out, zip_file, preview, file_selector, state]
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
)
|
| 96 |
|
| 97 |
file_selector.change(
|
| 98 |
-
lambda name, state: state["bundle"]["files"].get(name, ""),
|
| 99 |
inputs=[file_selector, state],
|
| 100 |
outputs=file_viewer
|
| 101 |
)
|
| 102 |
|
| 103 |
-
iface.launch()
|
|
|
|
| 46 |
f.write(zip_bytes)
|
| 47 |
|
| 48 |
progress(0.9, desc="Generating preview...")
|
| 49 |
+
preview_html = extract_react_preview(code_bundle.get("full_code", ""))
|
| 50 |
|
| 51 |
progress(1.0, desc="Done!")
|
| 52 |
+
return code_bundle.get("full_code", ""), "generated_app.zip", preview_html, code_bundle.get("files", {}), state
|
| 53 |
|
| 54 |
with gr.Blocks(title="Auto App Builder") as iface:
|
| 55 |
gr.Markdown("# ⚡ Auto App Builder (Gemini Powered)\n_Powered by Google Gemini API_")
|
|
|
|
| 77 |
def update_file_tree(code, zip_name, preview_path, files, state):
|
| 78 |
if isinstance(files, dict) and len(files) > 0:
|
| 79 |
keys = list(files.keys())
|
| 80 |
+
default_key = keys[0] if keys else None
|
| 81 |
+
return gr.update(choices=keys, value=default_key), files.get(default_key, "")
|
| 82 |
else:
|
| 83 |
return gr.update(choices=[], value=None), ""
|
| 84 |
|
| 85 |
btn.click(
|
| 86 |
fn=run_app,
|
| 87 |
inputs=[inp, enh, gr.State(""), state],
|
| 88 |
+
outputs=[code_out, zip_file, preview, file_selector, state]
|
| 89 |
+
).then(
|
| 90 |
+
fn=update_file_tree,
|
| 91 |
+
inputs=[code_out, zip_file, preview, state["bundle"]["files"] if state else {}, state],
|
| 92 |
+
outputs=[file_selector, file_viewer]
|
| 93 |
)
|
| 94 |
+
|
| 95 |
btn_enh.click(
|
| 96 |
fn=run_app,
|
| 97 |
inputs=[inp, enh, gr.State("Enhance"), state],
|
| 98 |
+
outputs=[code_out, zip_file, preview, file_selector, state]
|
| 99 |
+
).then(
|
| 100 |
+
fn=update_file_tree,
|
| 101 |
+
inputs=[code_out, zip_file, preview, state["bundle"]["files"] if state else {}, state],
|
| 102 |
+
outputs=[file_selector, file_viewer]
|
| 103 |
)
|
| 104 |
|
| 105 |
file_selector.change(
|
| 106 |
+
lambda name, state: state["bundle"]["files"].get(name, "") if state and "bundle" in state else "",
|
| 107 |
inputs=[file_selector, state],
|
| 108 |
outputs=file_viewer
|
| 109 |
)
|
| 110 |
|
| 111 |
+
iface.launch()
|