Spaces:
Sleeping
Sleeping
| # UI Generator Hugging Face Space - MVP | |
| # Requirements: gradio, transformers, torch | |
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| # Load an open-source code generation model (you can swap with DeepSeek-Coder, CodeLlama, etc.) | |
| model_id = "Salesforce/codegen-350M-mono" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained(model_id) | |
| generator = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| def generate_ui(platform, framework, ui_prompt): | |
| prompt = f""" | |
| You are an expert {framework} developer. | |
| Generate full code for a {platform} UI screen based on the following description: | |
| "{ui_prompt}" | |
| Please include necessary imports and use best practices. | |
| """ | |
| output = generator(prompt, max_length=512, do_sample=True, temperature=0.7)[0]["generated_text"] | |
| return output.strip() | |
| interface = gr.Interface( | |
| fn=generate_ui, | |
| inputs=[ | |
| gr.Dropdown(["Android", "iOS"], label="Platform"), | |
| gr.Dropdown(["Flutter", "Kotlin XML", "SwiftUI", "React Native"], label="Framework"), | |
| gr.Textbox(lines=4, label="UI Prompt", placeholder="e.g. Login screen with email & password, dark theme") | |
| ], | |
| outputs=gr.Code(label="Generated UI Code"), | |
| title="Prompt-to-UI Code Generator", | |
| description="Generate Android/iOS UI code in Flutter, SwiftUI, XML, or React Native by just describing the layout." | |
| ) | |
| interface.launch() | |