SHAILJA1 commited on
Commit
ac734ef
·
verified ·
1 Parent(s): 2356c4e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load pretrained model (replace with a fine-tuned UI generator if available)
5
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-small")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-small")
7
+
8
+ # Function to convert text to UI code
9
+ def text_to_ui(description):
10
+ inputs = tokenizer(description, return_tensors="pt")
11
+ outputs = model.generate(**inputs, max_length=256)
12
+ ui_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+
14
+ # Wrap in HTML body if not already
15
+ if "<html>" not in ui_code.lower():
16
+ ui_code = f"""
17
+ <html>
18
+ <head>
19
+ <style>
20
+ body {{ font-family: Arial, sans-serif; padding: 20px; }}
21
+ input, button {{ padding: 10px; margin: 5px; }}
22
+ </style>
23
+ </head>
24
+ <body>
25
+ {ui_code}
26
+ </body>
27
+ </html>
28
+ """
29
+ return ui_code, ui_code # return for both code display and HTML preview
30
+
31
+ # Gradio interface
32
+ iface = gr.Interface(
33
+ fn=text_to_ui,
34
+ inputs=gr.Textbox(lines=3, placeholder="Describe the UI you want..."),
35
+ outputs=[
36
+ gr.Code(label="Generated UI Code", language="html"),
37
+ gr.HTML(label="Preview")
38
+ ],
39
+ title="Text-to-UI Generator",
40
+ description="Enter a text description and generate HTML/CSS UI code with live preview."
41
+ )
42
+
43
+ # Launch the interface
44
+ iface.launch()