tiahchia commited on
Commit
75abf31
·
verified ·
1 Parent(s): e3432b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -18,10 +18,22 @@ def run_python(code):
18
  def run_web(code):
19
  return f'<iframe style="width:100%; height:100%; border:none; border-radius:8px; background:#1e1e1e;" srcdoc="{code}"></iframe>'
20
 
 
 
 
 
 
 
 
 
21
  # --- Main runner ---
22
  def run_code(code, lang):
23
  if lang == "Python":
24
  return run_python(code)
 
 
 
 
25
  else:
26
  return run_web(code)
27
 
@@ -44,6 +56,18 @@ h1 { color:#F714C5; text-align:center; }
44
  </body>
45
  </html>"""
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # --- Gradio app ---
48
  with gr.Blocks(css="""
49
  body {
@@ -53,9 +77,8 @@ body {
53
  color:#e0e0e0;
54
  background: linear-gradient(to bottom, #0a0a23, #1a0a3a, #00001a);
55
  }
56
-
57
  .gradio-container { max-width:1200px; margin:auto; padding:20px; }
58
- .gr-column { display:flex; flex-direction: column; gap:0px !important; }
59
  #editor-container, #output-panel {
60
  width:100% !important;
61
  margin:0 !important;
@@ -121,11 +144,11 @@ canvas#particles { position:fixed; top:0; left:0; width:100%; height:100%; z-ind
121
  </h2>
122
  """)
123
 
124
- # --- Compact Language selector (no label) ---
125
  lang_selector = gr.Radio(
126
- choices=["Python", "Web (HTML/CSS/JS)","JavaScript", "Bash"],
127
  value="Web (HTML/CSS/JS)",
128
- label=None # Removed label for compact look
129
  )
130
 
131
  # --- Vertical layout: output on top ---
@@ -152,7 +175,15 @@ canvas#particles { position:fixed; top:0; left:0; width:100%; height:100%; z-ind
152
 
153
  # --- Update starter template on language change ---
154
  def update_template(lang):
155
- return starter_python if lang == "Python" else starter_web
 
 
 
 
 
 
 
 
156
  lang_selector.change(update_template, inputs=lang_selector, outputs=code_input)
157
 
158
  # --- Run code ---
 
18
  def run_web(code):
19
  return f'<iframe style="width:100%; height:100%; border:none; border-radius:8px; background:#1e1e1e;" srcdoc="{code}"></iframe>'
20
 
21
+ # --- JavaScript runner ---
22
+ def run_js(code):
23
+ return f'<iframe style="width:100%; height:100%; border:none; border-radius:8px; background:#1e1e1e;" srcdoc="<script>{html.escape(code)}</script>"></iframe>'
24
+
25
+ # --- Bash runner (simulated) ---
26
+ def run_bash(code):
27
+ return f'<pre style="color:#00ff00; font-family: monospace;">$ {html.escape(code)}\nCommand simulated.</pre>'
28
+
29
  # --- Main runner ---
30
  def run_code(code, lang):
31
  if lang == "Python":
32
  return run_python(code)
33
+ elif lang == "JavaScript":
34
+ return run_js(code)
35
+ elif lang == "Bash":
36
+ return run_bash(code)
37
  else:
38
  return run_web(code)
39
 
 
56
  </body>
57
  </html>"""
58
 
59
+ starter_js = """// JavaScript example
60
+ console.log("Hello JavaScript!");
61
+ for(let i=0;i<5;i++){
62
+ console.log("Line "+(i+1));
63
+ }"""
64
+
65
+ starter_bash = """# Bash example
66
+ echo "Hello Bash!"
67
+ for i in {1..5}; do
68
+ echo "Line $i"
69
+ done"""
70
+
71
  # --- Gradio app ---
72
  with gr.Blocks(css="""
73
  body {
 
77
  color:#e0e0e0;
78
  background: linear-gradient(to bottom, #0a0a23, #1a0a3a, #00001a);
79
  }
 
80
  .gradio-container { max-width:1200px; margin:auto; padding:20px; }
81
+ .gr-column { display:flex; flex-direction: column; gap:8px !important; }
82
  #editor-container, #output-panel {
83
  width:100% !important;
84
  margin:0 !important;
 
144
  </h2>
145
  """)
146
 
147
+ # --- Language selector without label ---
148
  lang_selector = gr.Radio(
149
+ choices=["Python", "Web (HTML/CSS/JS)", "JavaScript", "Bash"],
150
  value="Web (HTML/CSS/JS)",
151
+ label=None # This removes "Select Language"
152
  )
153
 
154
  # --- Vertical layout: output on top ---
 
175
 
176
  # --- Update starter template on language change ---
177
  def update_template(lang):
178
+ if lang == "Python":
179
+ return starter_python
180
+ elif lang == "JavaScript":
181
+ return starter_js
182
+ elif lang == "Bash":
183
+ return starter_bash
184
+ else:
185
+ return starter_web
186
+
187
  lang_selector.change(update_template, inputs=lang_selector, outputs=code_input)
188
 
189
  # --- Run code ---