|
|
import gradio as gr |
|
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-small") |
|
|
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-small") |
|
|
|
|
|
|
|
|
def text_to_ui(description): |
|
|
inputs = tokenizer(description, return_tensors="pt") |
|
|
outputs = model.generate(**inputs, max_length=256) |
|
|
ui_code = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
|
|
|
if "<html>" not in ui_code.lower(): |
|
|
ui_code = f""" |
|
|
<html> |
|
|
<head> |
|
|
<style> |
|
|
body {{ font-family: Arial, sans-serif; padding: 20px; }} |
|
|
input, button {{ padding: 10px; margin: 5px; }} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
{ui_code} |
|
|
</body> |
|
|
</html> |
|
|
""" |
|
|
return ui_code, ui_code |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=text_to_ui, |
|
|
inputs=gr.Textbox(lines=3, placeholder="Describe the UI you want..."), |
|
|
outputs=[ |
|
|
gr.Code(label="Generated UI Code", language="html"), |
|
|
gr.HTML(label="Preview") |
|
|
], |
|
|
title="Text-to-UI Generator", |
|
|
description="Enter a text description and generate HTML/CSS UI code with live preview." |
|
|
) |
|
|
|
|
|
|
|
|
iface.launch() |
|
|
|