import gradio as gr from transformers import AutoTokenizer, AutoModelForSeq2SeqLM # Load pretrained model (replace with a fine-tuned UI generator if available) tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-small") model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-small") # Function to convert text to UI code 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) # Wrap in HTML body if not already if "" not in ui_code.lower(): ui_code = f""" {ui_code} """ return ui_code, ui_code # return for both code display and HTML preview # Gradio interface 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." ) # Launch the interface iface.launch()