Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,30 @@ def interface():
|
|
24 |
code_input.change(
|
25 |
fn=update_ui,
|
26 |
inputs=code_input,
|
27 |
-
outputs=[ui_preview, error_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
)
|
29 |
|
30 |
# Add example section
|
@@ -102,8 +125,8 @@ def interface():
|
|
102 |
for code, label in example_codes:
|
103 |
button = gr.Button(label)
|
104 |
example_buttons.append(button)
|
105 |
-
|
106 |
-
button.click(fn=update_ui, inputs=code, outputs=code_input)
|
107 |
|
108 |
return demo
|
109 |
|
|
|
24 |
code_input.change(
|
25 |
fn=update_ui,
|
26 |
inputs=code_input,
|
27 |
+
outputs=[ui_preview, error_output],
|
28 |
+
js="""
|
29 |
+
function(code) {
|
30 |
+
// Create a temporary div to parse the HTML/CSS/JS
|
31 |
+
const tempDiv = document.createElement('div');
|
32 |
+
tempDiv.innerHTML = code;
|
33 |
+
|
34 |
+
// Handle JavaScript by creating new script elements
|
35 |
+
const scripts = tempDiv.querySelectorAll('scriptDebug');
|
36 |
+
scripts.forEach(script => {
|
37 |
+
const newScript = document.createElement('script');
|
38 |
+
newScript.textContent = script.textContent;
|
39 |
+
document.body.appendChild(newScript);
|
40 |
+
script.remove(); // Remove original script to avoid double execution
|
41 |
+
});
|
42 |
+
|
43 |
+
// Wrap the content in a styled div for better presentation
|
44 |
+
return `
|
45 |
+
<div style="border: 1px solid #ccc; padding: 10px; height: 400px; overflow: auto;">
|
46 |
+
${tempDiv.innerHTML}
|
47 |
+
</div>
|
48 |
+
`;
|
49 |
+
}
|
50 |
+
"""
|
51 |
)
|
52 |
|
53 |
# Add example section
|
|
|
125 |
for code, label in example_codes:
|
126 |
button = gr.Button(label)
|
127 |
example_buttons.append(button)
|
128 |
+
button.click(fn=lambda x=code: x, outputs=code_input)
|
129 |
+
#button.click(fn=update_ui, inputs=code, outputs=code_input)
|
130 |
|
131 |
return demo
|
132 |
|