Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
def generate_ui(platform, framework,
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
interface = gr.Interface(
|
| 12 |
fn=generate_ui,
|
| 13 |
inputs=[
|
| 14 |
-
gr.Dropdown(["Android","iOS"], label="Platform"),
|
| 15 |
-
gr.Dropdown(["Flutter","Kotlin XML","SwiftUI","
|
| 16 |
-
gr.Textbox(lines=4, placeholder="
|
| 17 |
],
|
| 18 |
-
outputs=gr.Code(label="Generated UI Code")
|
|
|
|
|
|
|
| 19 |
)
|
|
|
|
| 20 |
interface.launch()
|
|
|
|
| 1 |
+
# UI Generator Hugging Face Space - MVP
|
| 2 |
+
# Requirements: gradio, transformers, torch
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 6 |
|
| 7 |
+
# Load an open-source code generation model (you can swap with DeepSeek-Coder, CodeLlama, etc.)
|
| 8 |
+
model_id = "Salesforce/codegen-350M-mono"
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 11 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 12 |
|
| 13 |
+
def generate_ui(platform, framework, ui_prompt):
|
| 14 |
+
prompt = f"""
|
| 15 |
+
You are an expert {framework} developer.
|
| 16 |
+
Generate full code for a {platform} UI screen based on the following description:
|
| 17 |
+
"{ui_prompt}"
|
| 18 |
+
Please include necessary imports and use best practices.
|
| 19 |
+
"""
|
| 20 |
+
output = generator(prompt, max_length=512, do_sample=True, temperature=0.7)[0]["generated_text"]
|
| 21 |
+
return output.strip()
|
| 22 |
|
| 23 |
interface = gr.Interface(
|
| 24 |
fn=generate_ui,
|
| 25 |
inputs=[
|
| 26 |
+
gr.Dropdown(["Android", "iOS"], label="Platform"),
|
| 27 |
+
gr.Dropdown(["Flutter", "Kotlin XML", "SwiftUI", "React Native"], label="Framework"),
|
| 28 |
+
gr.Textbox(lines=4, label="UI Prompt", placeholder="e.g. Login screen with email & password, dark theme")
|
| 29 |
],
|
| 30 |
+
outputs=gr.Code(label="Generated UI Code"),
|
| 31 |
+
title="Prompt-to-UI Code Generator",
|
| 32 |
+
description="Generate Android/iOS UI code in Flutter, SwiftUI, XML, or React Native by just describing the layout."
|
| 33 |
)
|
| 34 |
+
|
| 35 |
interface.launch()
|