broadfield-dev commited on
Commit
21446ed
·
verified ·
1 Parent(s): ae7d8a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -25,7 +25,29 @@ def interface():
25
  fn=update_ui,
26
  inputs=code_input,
27
  outputs=[ui_preview, error_output],
28
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  )
30
 
31
  # Add example section
@@ -99,33 +121,11 @@ def interface():
99
  </script>
100
  """, "Snake Game"),
101
  ]
102
- js_in="""
103
- function(code) {
104
- // Create a temporary div to parse the HTML/CSS/JS
105
- const tempDiv = document.createElement('div');
106
- tempDiv.innerHTML = code;
107
-
108
- // Handle JavaScript by creating new script elements
109
- const scripts = tempDiv.querySelectorAll('scriptDebug');
110
- scripts.forEach(script => {
111
- const newScript = document.createElement('script');
112
- newScript.textContent = script.textContent;
113
- document.body.appendChild(newScript);
114
- script.remove(); // Remove original script to avoid double execution
115
- });
116
-
117
- // Wrap the content in a styled div for better presentation
118
- return `
119
- <div style="border: 1px solid #ccc; padding: 10px; height: 400px; overflow: auto;">
120
- ${tempDiv.innerHTML}
121
- </div>
122
- `;
123
- }
124
- """
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,js=js_in)
129
  #button.click(fn=update_ui, inputs=code, outputs=code_input)
130
 
131
  return demo
 
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
 
121
  </script>
122
  """, "Snake Game"),
123
  ]
124
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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