Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,16 @@ import gradio as gr
|
|
| 6 |
# -----------------------
|
| 7 |
# Configure Gemini API
|
| 8 |
# -----------------------
|
| 9 |
-
genai.configure(api_key=os.environ["GENAI_API_KEY"])
|
| 10 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
| 11 |
|
| 12 |
# Configure wkhtmltoimage path
|
| 13 |
IMGKIT_CONFIG = imgkit.config(wkhtmltoimage="/usr/bin/wkhtmltoimage")
|
| 14 |
|
| 15 |
# -----------------------
|
| 16 |
-
# Function: Generate
|
| 17 |
# -----------------------
|
| 18 |
def generate_mockup(user_prompt):
|
| 19 |
-
"""
|
| 20 |
-
Convert user description into Power Apps mockup (PNG only)
|
| 21 |
-
"""
|
| 22 |
system_prompt = (
|
| 23 |
"You are a Power Apps mockup generator. "
|
| 24 |
"Convert user descriptions into complete HTML + CSS code that looks like a Power Apps mobile screen. "
|
|
@@ -35,31 +32,36 @@ def generate_mockup(user_prompt):
|
|
| 35 |
|
| 36 |
# Generate PNG image
|
| 37 |
output_img = "mockup.png"
|
| 38 |
-
imgkit.from_file("mockup.html", output_img
|
| 39 |
|
| 40 |
-
return output_img
|
| 41 |
|
| 42 |
except Exception as e:
|
| 43 |
-
return f"❌ Error: {e}"
|
| 44 |
|
| 45 |
# -----------------------
|
| 46 |
-
# Gradio Interface
|
| 47 |
# -----------------------
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
-
gr.Markdown("## ⚡ Power Apps Mockup Generator (Gemini + HTML
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
user_input = gr.Textbox(
|
| 52 |
-
label="Describe your Power Apps mockup screen",
|
| 53 |
-
placeholder="Example: A login screen with username, password, and a login button",
|
| 54 |
-
lines=3
|
| 55 |
-
)
|
| 56 |
generate_btn = gr.Button("Generate Mockup")
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
generate_btn.click(
|
| 60 |
fn=generate_mockup,
|
| 61 |
inputs=user_input,
|
| 62 |
-
outputs=image_output
|
| 63 |
)
|
| 64 |
|
| 65 |
demo.launch()
|
|
|
|
| 6 |
# -----------------------
|
| 7 |
# Configure Gemini API
|
| 8 |
# -----------------------
|
| 9 |
+
genai.configure(api_key=os.environ["GENAI_API_KEY"])
|
| 10 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
| 11 |
|
| 12 |
# Configure wkhtmltoimage path
|
| 13 |
IMGKIT_CONFIG = imgkit.config(wkhtmltoimage="/usr/bin/wkhtmltoimage")
|
| 14 |
|
| 15 |
# -----------------------
|
| 16 |
+
# Function: Generate HTML from user description
|
| 17 |
# -----------------------
|
| 18 |
def generate_mockup(user_prompt):
|
|
|
|
|
|
|
|
|
|
| 19 |
system_prompt = (
|
| 20 |
"You are a Power Apps mockup generator. "
|
| 21 |
"Convert user descriptions into complete HTML + CSS code that looks like a Power Apps mobile screen. "
|
|
|
|
| 32 |
|
| 33 |
# Generate PNG image
|
| 34 |
output_img = "mockup.png"
|
| 35 |
+
imgkit.from_file("mockup.html", output_img)
|
| 36 |
|
| 37 |
+
return html_code, output_img
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
+
return f"❌ Error: {e}", None
|
| 41 |
|
| 42 |
# -----------------------
|
| 43 |
+
# Gradio Interface
|
| 44 |
# -----------------------
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
+
gr.Markdown("## ⚡ Power Apps Mockup Generator (Gemini + HTML + PNG)")
|
| 47 |
+
|
| 48 |
+
with gr.Row():
|
| 49 |
+
user_input = gr.Textbox(
|
| 50 |
+
label="Describe your Power Apps mockup screen",
|
| 51 |
+
placeholder="Example: A login screen with username, password, and a login button",
|
| 52 |
+
lines=3
|
| 53 |
+
)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
generate_btn = gr.Button("Generate Mockup")
|
| 56 |
+
|
| 57 |
+
with gr.Row():
|
| 58 |
+
html_output = gr.Code(label="Generated HTML + CSS", language="html")
|
| 59 |
+
image_output = gr.Image(label="Mockup Preview")
|
| 60 |
|
| 61 |
generate_btn.click(
|
| 62 |
fn=generate_mockup,
|
| 63 |
inputs=user_input,
|
| 64 |
+
outputs=[html_output, image_output]
|
| 65 |
)
|
| 66 |
|
| 67 |
demo.launch()
|