tiahchia commited on
Commit
e4d445f
·
verified ·
1 Parent(s): 008a245

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -47
app.py CHANGED
@@ -25,7 +25,6 @@ def run_code(code, lang):
25
  else:
26
  return run_web(code)
27
 
28
- # Starter templates
29
  starter_python = """# Python example
30
  print("Hello World!")
31
  for i in range(5):
@@ -44,50 +43,37 @@ h1 { color:#F714C5; text-align:center; }
44
  </body>
45
  </html>"""
46
 
47
- with gr.Blocks(css=f"""
48
- /* Dark night sky background with subtle particles */
49
- body {{
50
- margin:0;
51
- padding:0;
52
  font-family:'Poppins', sans-serif;
53
- background: linear-gradient(to bottom, #0a0a23, #00001a);
54
  overflow-x:hidden;
55
  color:#e0e0e0;
 
56
  position: relative;
57
- }}
58
- /* subtle particle animation */
59
- body::before {{
60
- content:'';
61
- position:absolute;
62
- top:0; left:0;
63
- width:100%; height:100%;
64
- background-image: radial-gradient(white 0.5px, transparent 0.5px);
65
- background-size: 20px 20px;
66
- opacity: 0.15;
67
- pointer-events:none;
68
- animation: moveStars 180s linear infinite;
69
- z-index:0;
70
- }}
71
- @keyframes moveStars {{
72
- from {{ background-position: 0 0; }}
73
- to {{ background-position: 1000px 1000px; }}
74
- }}
75
-
76
- .gradio-container {{
77
  max-width:1900px;
78
- margin:auto;
79
  padding:20px;
80
- position:relative;
81
- z-index:1; /* above particle layer */
82
- }}
83
 
84
- .gr-row {{ display:flex; gap:20px; margin-top:20px; }}
 
 
 
 
85
 
86
- /* Editor 80% width, output 20% */
87
- #editor-container {{ flex:0.8; }}
88
- #output-panel {{ flex:0.2; }}
 
89
 
90
- .output-panel {{
91
  background:#1e1e1e;
92
  border-radius:8px;
93
  box-shadow:0 4px 8px rgba(0,0,0,0.5);
@@ -97,24 +83,67 @@ body::before {{
97
  color: #00ff00;
98
  white-space: pre-wrap;
99
  overflow:auto;
100
- }}
101
 
102
- #editor-container .CodeMirror {{
103
  height:600px;
104
  border-radius:8px;
105
  font-family: monospace;
106
  font-size:14px;
107
  white-space: pre-wrap;
108
  overflow-wrap: break-word;
109
- }}
110
-
111
- .gr-radio {{ color:#e0e0e0; margin-bottom:16px; }}
112
- button, .gr-button {{ background-color:#F714C5 !important; color:#fff !important; border-radius:6px !important; padding:10px 20px !important; }}
113
- footer {{ display:none !important; }}
114
- header {{ background:#000000; padding:16px; color:#F714C5; font-size:1.6em; text-align:center; margin-top:20px; }}
115
- header img {{ vertical-align:middle; height:20px; margin-right:8px; }}
 
116
  """) as demo:
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  # Intro header
119
  gr.Markdown("""
120
  <h2 style="color:#F714C5; text-align:center; margin-bottom:10px;">
@@ -122,7 +151,7 @@ header img {{ vertical-align:middle; height:20px; margin-right:8px; }}
122
  </h2>
123
  """)
124
 
125
- # Language selector at the top
126
  lang_selector = gr.Radio(
127
  choices=["Python", "Web (HTML/CSS/JS)"],
128
  value="Web (HTML/CSS/JS)",
@@ -160,4 +189,3 @@ header img {{ vertical-align:middle; height:20px; margin-right:8px; }}
160
  render_button.click(run_code, inputs=[code_input, lang_selector], outputs=output_frame)
161
 
162
  demo.launch()
163
-
 
25
  else:
26
  return run_web(code)
27
 
 
28
  starter_python = """# Python example
29
  print("Hello World!")
30
  for i in range(5):
 
43
  </body>
44
  </html>"""
45
 
46
+ with gr.Blocks(css="""
47
+ /* Dark navy background with Canvas particles */
48
+ body {
49
+ margin:0; padding:0;
 
50
  font-family:'Poppins', sans-serif;
 
51
  overflow-x:hidden;
52
  color:#e0e0e0;
53
+ background: linear-gradient(to bottom, #0a0a23, #00001a);
54
  position: relative;
55
+ }
56
+
57
+ .gradio-container {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  max-width:1900px;
59
+ margin:auto;
60
  padding:20px;
61
+ position: relative;
62
+ z-index:1;
63
+ }
64
 
65
+ .gr-row {
66
+ display:flex;
67
+ gap:20px;
68
+ margin-top:20px;
69
+ }
70
 
71
+ /* Equal width editor/output */
72
+ #editor-container, #output-panel {
73
+ flex:0.5;
74
+ }
75
 
76
+ .output-panel {
77
  background:#1e1e1e;
78
  border-radius:8px;
79
  box-shadow:0 4px 8px rgba(0,0,0,0.5);
 
83
  color: #00ff00;
84
  white-space: pre-wrap;
85
  overflow:auto;
86
+ }
87
 
88
+ #editor-container .CodeMirror {
89
  height:600px;
90
  border-radius:8px;
91
  font-family: monospace;
92
  font-size:14px;
93
  white-space: pre-wrap;
94
  overflow-wrap: break-word;
95
+ }
96
+
97
+ .gr-radio { color:#e0e0e0; margin-bottom:16px; }
98
+ button, .gr-button { background-color:#F714C5 !important; color:#fff !important; border-radius:6px !important; padding:10px 20px !important; }
99
+ footer { display:none !important; }
100
+ header { background:#000000; padding:16px; color:#F714C5; font-size:1.6em; text-align:center; margin-top:20px; }
101
+ header img { vertical-align:middle; height:20px; margin-right:8px; }
102
+ canvas#particles { position:fixed; top:0; left:0; width:100%; height:100%; z-index:0; pointer-events:none; }
103
  """) as demo:
104
 
105
+ # Canvas for particles
106
+ gr.HTML("""
107
+ <canvas id="particles"></canvas>
108
+ <script>
109
+ const canvas = document.getElementById('particles');
110
+ const ctx = canvas.getContext('2d');
111
+ let stars = [];
112
+ function resize() {
113
+ canvas.width = window.innerWidth;
114
+ canvas.height = window.innerHeight;
115
+ }
116
+ window.addEventListener('resize', resize);
117
+ resize();
118
+ for(let i=0;i<150;i++){
119
+ stars.push({
120
+ x: Math.random()*canvas.width,
121
+ y: Math.random()*canvas.height,
122
+ r: Math.random()*1.5,
123
+ dx: (Math.random()-0.5)*0.3,
124
+ dy: (Math.random()-0.5)*0.3
125
+ });
126
+ }
127
+ function animate(){
128
+ ctx.clearRect(0,0,canvas.width,canvas.height);
129
+ for(let s of stars){
130
+ ctx.beginPath();
131
+ ctx.arc(s.x,s.y,s.r,0,Math.PI*2);
132
+ ctx.fillStyle='white';
133
+ ctx.fill();
134
+ s.x += s.dx;
135
+ s.y += s.dy;
136
+ if(s.x<0) s.x=canvas.width;
137
+ if(s.x>canvas.width) s.x=0;
138
+ if(s.y<0) s.y=canvas.height;
139
+ if(s.y>canvas.height) s.y=0;
140
+ }
141
+ requestAnimationFrame(animate);
142
+ }
143
+ animate();
144
+ </script>
145
+ """)
146
+
147
  # Intro header
148
  gr.Markdown("""
149
  <h2 style="color:#F714C5; text-align:center; margin-bottom:10px;">
 
151
  </h2>
152
  """)
153
 
154
+ # Language selector
155
  lang_selector = gr.Radio(
156
  choices=["Python", "Web (HTML/CSS/JS)"],
157
  value="Web (HTML/CSS/JS)",
 
189
  render_button.click(run_code, inputs=[code_input, lang_selector], outputs=output_frame)
190
 
191
  demo.launch()