Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import re
|
3 |
+
|
4 |
+
def update_ui(code):
|
5 |
+
try:
|
6 |
+
# This is a simplistic approach. In reality, you'd parse HTML and CSS to render UI.
|
7 |
+
html_pattern = r'<[^>]+>'
|
8 |
+
css_pattern = r'{[^}]*}'
|
9 |
+
|
10 |
+
html = re.findall(html_pattern, code)
|
11 |
+
css = re.findall(css_pattern, code)
|
12 |
+
|
13 |
+
# For demonstration, we'll just combine HTML and CSS into one string.
|
14 |
+
ui_output = ''.join(html) + ''.join(css)
|
15 |
+
return ui_output, None
|
16 |
+
except Exception as e:
|
17 |
+
return "", str(e)
|
18 |
+
|
19 |
+
def interface():
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("# Learn Frontend UI")
|
22 |
+
with gr.Row():
|
23 |
+
code_input = gr.Code(label="Write your HTML/CSS here", language="html")
|
24 |
+
with gr.Column():
|
25 |
+
ui_preview = gr.HTML(label="UI Preview")
|
26 |
+
error_output = gr.Textbox(label="Error", interactive=False)
|
27 |
+
|
28 |
+
code_input.change(fn=update_ui, inputs=code_input, outputs=[ui_preview, error_output])
|
29 |
+
|
30 |
+
return demo
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo = interface()
|
34 |
+
demo.launch()
|