Update app.py
Browse files
app.py
CHANGED
|
@@ -4,53 +4,52 @@ import gradio as gr
|
|
| 4 |
import asyncio
|
| 5 |
from pyppeteer import launch
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
| 8 |
genai.configure(api_key=os.environ["GENAI_API_KEY"])
|
| 9 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
await page.setContent(html_code)
|
| 16 |
-
await page.screenshot({'path': output_img, 'fullPage': True})
|
| 17 |
-
await browser.close()
|
| 18 |
-
return output_img
|
| 19 |
-
|
| 20 |
-
def generate_mockup(user_prompt):
|
| 21 |
system_prompt = (
|
| 22 |
"You are a Power Apps mockup generator. "
|
| 23 |
"Convert user descriptions into complete HTML + CSS code that looks like a Power Apps mobile screen. "
|
| 24 |
"Do NOT include JSON or explanations. Only return valid HTML + CSS."
|
| 25 |
)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
)
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
demo.launch()
|
|
|
|
| 4 |
import asyncio
|
| 5 |
from pyppeteer import launch
|
| 6 |
|
| 7 |
+
# -----------------------
|
| 8 |
+
# Configure Gemini API
|
| 9 |
+
# -----------------------
|
| 10 |
genai.configure(api_key=os.environ["GENAI_API_KEY"])
|
| 11 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
| 12 |
|
| 13 |
+
# -----------------------
|
| 14 |
+
# Generate HTML from prompt
|
| 15 |
+
# -----------------------
|
| 16 |
+
def generate_mockup_html(user_prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
system_prompt = (
|
| 18 |
"You are a Power Apps mockup generator. "
|
| 19 |
"Convert user descriptions into complete HTML + CSS code that looks like a Power Apps mobile screen. "
|
| 20 |
"Do NOT include JSON or explanations. Only return valid HTML + CSS."
|
| 21 |
)
|
| 22 |
+
response = model.generate_content(system_prompt + "\n" + user_prompt)
|
| 23 |
+
return response.text
|
| 24 |
+
|
| 25 |
+
# -----------------------
|
| 26 |
+
# Convert HTML → PNG
|
| 27 |
+
# -----------------------
|
| 28 |
+
async def render_html_to_png(html_code, output_file="mockup.png"):
|
| 29 |
+
browser = await launch(args=["--no-sandbox"])
|
| 30 |
+
page = await browser.newPage()
|
| 31 |
+
await page.setContent(html_code)
|
| 32 |
+
await page.screenshot({"path": output_file, "fullPage": True})
|
| 33 |
+
await browser.close()
|
| 34 |
+
return output_file
|
| 35 |
+
|
| 36 |
+
# -----------------------
|
| 37 |
+
# Full pipeline
|
| 38 |
+
# -----------------------
|
| 39 |
+
def gradio_mockup(user_prompt):
|
| 40 |
+
html_code = generate_mockup_html(user_prompt)
|
| 41 |
+
asyncio.get_event_loop().run_until_complete(render_html_to_png(html_code))
|
| 42 |
+
return "mockup.png"
|
| 43 |
+
|
| 44 |
+
# -----------------------
|
| 45 |
+
# Gradio Interface
|
| 46 |
+
# -----------------------
|
| 47 |
+
demo = gr.Interface(
|
| 48 |
+
fn=gradio_mockup,
|
| 49 |
+
inputs=gr.Textbox(label="Describe your PowerApps mockup screen", lines=3),
|
| 50 |
+
outputs=gr.Image(type="filepath", label="Generated Mockup"),
|
| 51 |
+
title="PowerApps Mockup Generator",
|
| 52 |
+
description="Enter your screen description and get a PowerApps-style mockup as an image."
|
| 53 |
+
)
|
| 54 |
|
| 55 |
demo.launch()
|