AZILS commited on
Commit
9dd1c50
·
verified ·
1 Parent(s): 7da8fbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +158 -145
app.py CHANGED
@@ -1,7 +1,7 @@
1
  #!/usr/bin/env python3
2
  """
3
- Enhanced Antigravity VS Code Interface - Dark Theme
4
- Provides status dashboard and easy access to VS Code features
5
  """
6
 
7
  from http.server import HTTPServer, BaseHTTPRequestHandler
@@ -9,9 +9,11 @@ import subprocess
9
  import sys
10
  import os
11
  import json
12
- import io
13
- from contextlib import redirect_stdout, redirect_stderr
14
  from urllib.parse import parse_qs
 
 
 
 
15
 
16
  class AntigravityHandler(BaseHTTPRequestHandler):
17
  def do_GET(self):
@@ -20,14 +22,14 @@ class AntigravityHandler(BaseHTTPRequestHandler):
20
  self.send_header('Content-type', 'text/html')
21
  self.end_headers()
22
 
23
- # Test antigravity package
24
  try:
25
  result = subprocess.run(['antigravity', '--version'],
26
  capture_output=True, text=True, timeout=5)
27
- antigravity_status = "Available" if result.returncode == 0 else "Error"
28
- antigravity_version = result.stdout.strip() if result.returncode == 0 else "Unable to determine"
29
  except Exception as e:
30
- antigravity_status = "Error"
31
  antigravity_version = str(e)
32
 
33
  # System info
@@ -41,7 +43,7 @@ class AntigravityHandler(BaseHTTPRequestHandler):
41
  <!DOCTYPE html>
42
  <html>
43
  <head>
44
- <title>Antigravity VS Code Sandbox</title>
45
  <style>
46
  body {{
47
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
@@ -134,6 +136,17 @@ class AntigravityHandler(BaseHTTPRequestHandler):
134
  background: #ffa947;
135
  transform: translateY(-2px);
136
  }}
 
 
 
 
 
 
 
 
 
 
 
137
  .status {{
138
  padding: 15px;
139
  border-radius: 8px;
@@ -150,6 +163,11 @@ class AntigravityHandler(BaseHTTPRequestHandler):
150
  color: #fb8500;
151
  border: 1px solid #fb8500;
152
  }}
 
 
 
 
 
153
  .pre {{
154
  background: #0d1117;
155
  color: #79c0ff;
@@ -169,167 +187,124 @@ class AntigravityHandler(BaseHTTPRequestHandler):
169
  margin: 10px 0;
170
  border: 2px solid #1f6feb;
171
  }}
172
- .code-editor {{
173
- width: 100%;
174
- height: 250px;
175
  background: #0d1117;
176
  color: #79c0ff;
177
  border: 1px solid #30363d;
178
- border-radius: 8px;
179
  padding: 12px;
180
- font-family: 'Courier New', monospace;
181
- font-size: 14px;
182
- resize: vertical;
183
- }}
184
- .output-box {{
185
- background: #0d1117;
186
- color: #39ff14;
187
- border: 1px solid #30363d;
188
  border-radius: 8px;
189
- padding: 15px;
190
- margin: 15px 0;
191
- min-height: 100px;
192
  font-family: 'Courier New', monospace;
193
- white-space: pre-wrap;
194
- word-wrap: break-word;
195
- max-height: 400px;
196
- overflow-y: auto;
197
- }}
198
- .error-box {{
199
- background: rgba(248, 81, 73, 0.15);
200
- color: #f85149;
201
- border: 1px solid #f85149;
202
- }}
203
- .success-box {{
204
- background: rgba(63, 185, 80, 0.15);
205
- color: #39ff14;
206
- border: 1px solid #3fb950;
207
  }}
208
  </style>
209
  </head>
210
  <body>
211
  <div class="container">
212
  <div class="header">
213
- <h1>🚀 Antigravity VS Code Sandbox</h1>
214
- <div class="vscode-badge">Full VS Code Environment</div>
215
- <p>Docker-based development environment with complete VS Code functionality</p>
216
  </div>
217
 
218
  <div class="grid">
219
  <div class="card">
220
- <h3> System Status</h3>
221
- <div class="status {'success' if antigravity_status == 'Available' else 'warning'}">
222
- Antigravity Package: {antigravity_status}
223
  </div>
224
  <div><strong>Version:</strong> {antigravity_version}</div>
225
- <div><strong>Platform:</strong> Ubuntu Docker Container</div>
226
  <div><strong>Python:</strong> {sys.version.split()[0]}</div>
227
- <div><strong>Working Directory:</strong> {os.getcwd()}</div>
 
228
  </div>
229
 
230
  <div class="card">
231
- <h3>🎯 Quick Actions</h3>
232
- <p>Launch VS Code features instantly:</p>
233
- <button onclick="alert('To start VS Code web server:\\n\\n1. Use terminal tab in your space\\n2. Run: antigravity --serve-web\\n\\nThis will launch VS Code in your browser!')" class="button green">
234
- 🌐 Start VS Code Web
235
  </button>
236
- <button onclick="alert('To start AI chat assistant:\\n\\n1. Use terminal tab in your space\\n2. Run: antigravity chat\\n\\nThis opens the coding AI assistant!')" class="button orange">
237
- 🤖 AI Chat Assistant
238
  </button>
239
- <button onclick="showVersion()" class="button">
240
- ℹ️ Version Info
241
  </button>
242
  </div>
243
 
244
  <div class="card">
245
- <h3>🛠️ VS Code Features</h3>
246
- <p>Available Antigravity commands:</p>
247
- <div class="pre">antigravity --serve-web # Start VS Code web
248
- antigravity chat # AI coding assistant
249
- antigravity --version # Check version
250
- antigravity --diff file1 file2 # Compare files
251
- antigravity --merge base left right output # Merge
252
- antigravity --new-window # New editor window
253
- antigravity --extensions-dir # Extension folder
254
- antigravity --list-extensions # List extensions
255
- antigravity --install-extension ext-id # Install extension</div>
256
  </div>
257
 
258
  <div class="card">
259
- <h3>📊 System Details</h3>
260
- <div class="terminal">{system_details}</div>
261
- <div style="margin-top: 15px; font-size: 0.9em; color: #8b949e;">
262
- <em>Container running on Hugging Face Spaces</em>
263
- </div>
264
  </div>
265
  </div>
266
 
267
  <div class="card" style="margin-top: 20px;">
268
- <h3>🚀 Development Environment Ready</h3>
269
- <p>Your Antigravity Docker Space is fully configured with:</p>
270
- <ul style="color: #e6edf3;">
271
- <li><strong>VS Code CLI:</strong> Full command-line interface</li>
272
- <li><strong>File Management:</strong> Open, edit, compare, and merge files</li>
273
- <li><strong>Extensions:</strong> Install and manage VS Code extensions</li>
274
- <li><strong>Web Interface:</strong> Run VS Code in your browser</li>
275
- <li><strong>AI Assistant:</strong> Built-in chat and coding help</li>
276
- <li><strong>Development Tools:</strong> Complete development environment</li>
277
- </ul>
278
  </div>
279
 
280
  <div class="card" style="margin-top: 20px;">
281
- <h3>💻 Python Code Executor</h3>
282
- <p>Execute Python code directly in your browser:</p>
283
- <form method="POST" action="/execute">
284
- <textarea class="code-editor" name="code" placeholder="# Enter your Python code here&#10;print('Hello, World!')&#10;&#10;# Try it out!"></textarea>
285
- <button type="submit" class="button green" style="margin-top: 10px;">
286
- ▶️ Run Code
287
- </button>
288
- <button type="reset" class="button" style="margin-top: 10px;">
289
- 🔄 Clear
290
- </button>
291
- </form>
292
- <div id="output"></div>
293
  </div>
294
  </div>
295
 
296
  <script>
297
- function showVersion() {{
298
- alert('Antigravity Version: {antigravity_version}\\n\\nThis is your VS Code command-line interface.\\nUse the terminal tab to run commands like:\\n• antigravity --serve-web\\n• antigravity chat\\n• antigravity --help');
 
 
 
 
 
 
 
 
 
299
  }}
300
 
301
- // Handle form submission
302
- document.addEventListener('DOMContentLoaded', function() {{
303
- const form = document.querySelector('form[action="/execute"]');
304
- if (form) {{
305
- form.addEventListener('submit', async function(e) {{
306
- e.preventDefault();
307
- const code = document.querySelector('textarea[name="code"]').value;
308
-
309
- if (!code.trim()) {{
310
- alert('Please enter some Python code!');
311
- return;
312
  }}
313
-
314
- try {{
315
- const response = await fetch('/execute', {{
316
- method: 'POST',
317
- body: new URLSearchParams({{ code: code }})
318
- }});
319
-
320
- const data = await response.json();
321
- const outputDiv = document.getElementById('output');
322
-
323
- const outputClass = data.error ? 'output-box error-box' : 'output-box success-box';
324
- outputDiv.innerHTML = '<strong>' + (data.error ? '❌ Error' : ' Output') + ':</strong><br>' +
325
- data.output.replace(/</g, '&lt;').replace(/>/g, '&gt;');
326
- outputDiv.className = outputClass;
327
- }} catch (err) {{
328
- alert('Error: ' + err.message);
329
  }}
330
- }});
331
- }}
332
- }});
333
  </script>
334
  </body>
335
  </html>
@@ -371,37 +346,75 @@ antigravity --install-extension ext-id # Install extension</div>
371
  print(f"[Antigravity VS Code] {format % args}")
372
 
373
  def do_POST(self):
374
- if self.path == '/execute':
375
- content_length = int(self.headers.get('Content-Length', 0))
376
- body = self.rfile.read(content_length).decode('utf-8')
377
- params = parse_qs(body)
378
- code = params.get('code', [''])[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
 
380
- # Capture output
381
- output_capture = io.StringIO()
382
- error_capture = io.StringIO()
383
- result = ""
 
 
384
 
385
  try:
386
- with redirect_stdout(output_capture), redirect_stderr(error_capture):
387
- exec(code)
388
- result = output_capture.getvalue()
389
- is_error = False
 
 
390
  except Exception as e:
391
- result = f"Error: {str(e)}\n{error_capture.getvalue()}"
392
- is_error = True
 
 
393
 
394
- # Send JSON response
 
 
395
  self.send_response(200)
396
  self.send_header('Content-type', 'application/json')
397
  self.end_headers()
398
 
399
- response = {
400
- 'success': not is_error,
401
- 'output': result if result else "(No output)",
402
- 'error': is_error
403
- }
 
 
 
 
 
 
 
 
404
  self.wfile.write(json.dumps(response).encode())
 
405
  else:
406
  self.send_response(404)
407
  self.end_headers()
 
1
  #!/usr/bin/env python3
2
  """
3
+ Antigravity VS Code IDE Launcher - Dark Theme
4
+ Launches the actual Antigravity VS Code IDE with agents support
5
  """
6
 
7
  from http.server import HTTPServer, BaseHTTPRequestHandler
 
9
  import sys
10
  import os
11
  import json
 
 
12
  from urllib.parse import parse_qs
13
+ import threading
14
+ import time
15
+
16
+ vscode_process = None
17
 
18
  class AntigravityHandler(BaseHTTPRequestHandler):
19
  def do_GET(self):
 
22
  self.send_header('Content-type', 'text/html')
23
  self.end_headers()
24
 
25
+ # Check Antigravity installation
26
  try:
27
  result = subprocess.run(['antigravity', '--version'],
28
  capture_output=True, text=True, timeout=5)
29
+ antigravity_status = "✅ Installed" if result.returncode == 0 else "❌ Not Available"
30
+ antigravity_version = result.stdout.strip() if result.returncode == 0 else "Error"
31
  except Exception as e:
32
+ antigravity_status = "Error"
33
  antigravity_version = str(e)
34
 
35
  # System info
 
43
  <!DOCTYPE html>
44
  <html>
45
  <head>
46
+ <title>Antigravity VS Code IDE</title>
47
  <style>
48
  body {{
49
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
 
136
  background: #ffa947;
137
  transform: translateY(-2px);
138
  }}
139
+ .button.red {{
140
+ background: #f85149;
141
+ }}
142
+ .button.red:hover {{
143
+ background: #ff7b72;
144
+ transform: translateY(-2px);
145
+ }}
146
+ .button:disabled {{
147
+ opacity: 0.5;
148
+ cursor: not-allowed;
149
+ }}
150
  .status {{
151
  padding: 15px;
152
  border-radius: 8px;
 
163
  color: #fb8500;
164
  border: 1px solid #fb8500;
165
  }}
166
+ .error {{
167
+ background: rgba(248, 81, 73, 0.15);
168
+ color: #f85149;
169
+ border: 1px solid #f85149;
170
+ }}
171
  .pre {{
172
  background: #0d1117;
173
  color: #79c0ff;
 
187
  margin: 10px 0;
188
  border: 2px solid #1f6feb;
189
  }}
190
+ .command-box {{
 
 
191
  background: #0d1117;
192
  color: #79c0ff;
193
  border: 1px solid #30363d;
 
194
  padding: 12px;
 
 
 
 
 
 
 
 
195
  border-radius: 8px;
196
+ margin: 10px 0;
 
 
197
  font-family: 'Courier New', monospace;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  }}
199
  </style>
200
  </head>
201
  <body>
202
  <div class="container">
203
  <div class="header">
204
+ <h1> Antigravity VS Code IDE</h1>
205
+ <div class="vscode-badge">Agents + Code Editor</div>
206
+ <p>Professional development environment with Antigravity agents</p>
207
  </div>
208
 
209
  <div class="grid">
210
  <div class="card">
211
+ <h3>📊 System Status</h3>
212
+ <div class="status {'success' if antigravity_status == '✅ Installed' else 'warning'}">
213
+ Antigravity: {antigravity_status}
214
  </div>
215
  <div><strong>Version:</strong> {antigravity_version}</div>
 
216
  <div><strong>Python:</strong> {sys.version.split()[0]}</div>
217
+ <div><strong>Platform:</strong> {sys.platform}</div>
218
+ <div><strong>Working Dir:</strong> {os.getcwd()}</div>
219
  </div>
220
 
221
  <div class="card">
222
+ <h3>🚀 Launch IDE</h3>
223
+ <p>Start Antigravity VS Code:</p>
224
+ <button onclick="launchIDE()" class="button green" style="width: 100%; margin-top: 10px;">
225
+ ▶️ Launch Antigravity IDE
226
  </button>
227
+ <button onclick="launchAgents()" class="button orange" style="width: 100%; margin-top: 10px;">
228
+ 🤖 Launch Agents
229
  </button>
230
+ <button onclick="launchChat()" class="button" style="width: 100%; margin-top: 10px;">
231
+ 💬 AI Chat
232
  </button>
233
  </div>
234
 
235
  <div class="card">
236
+ <h3>📝 Available Commands</h3>
237
+ <div class="pre" style="font-size: 12px;">antigravity --serve-web
238
+ antigravity chat
239
+ antigravity agents
240
+ antigravity --list-extensions
241
+ antigravity --help</div>
 
 
 
 
 
242
  </div>
243
 
244
  <div class="card">
245
+ <h3>🖥️ System Details</h3>
246
+ <div class="terminal" style="font-size: 12px;">{system_details}</div>
 
 
 
247
  </div>
248
  </div>
249
 
250
  <div class="card" style="margin-top: 20px;">
251
+ <h3> Antigravity Agents</h3>
252
+ <p>Use AI-powered agents to code, debug, and create:</p>
253
+ <div class="command-box">$ antigravity agents</div>
254
+ <p style="color: #8b949e; font-size: 14px;">Agents enable autonomous code generation, testing, and debugging with natural language commands.</p>
 
 
 
 
 
 
255
  </div>
256
 
257
  <div class="card" style="margin-top: 20px;">
258
+ <h3>📚 Quick Start</h3>
259
+ <ol style="color: #e6edf3;">
260
+ <li>Click <strong>"Launch Antigravity IDE"</strong> to open VS Code</li>
261
+ <li>Use <strong>"Launch Agents"</strong> to enable AI-powered coding</li>
262
+ <li>Type your requirements in natural language</li>
263
+ <li>Agents will generate and execute code automatically</li>
264
+ <li>Use AI Chat for questions and assistance</li>
265
+ </ol>
 
 
 
 
266
  </div>
267
  </div>
268
 
269
  <script>
270
+ function launchIDE() {{
271
+ fetch('/launch-ide', {{ method: 'POST' }})
272
+ .then(r => r.json())
273
+ .then(d => {{
274
+ if (d.success) {{
275
+ alert('✅ Antigravity VS Code IDE launched!\\n\\nCheck the terminal or open http://localhost:8000');
276
+ }} else {{
277
+ alert('❌ Error: ' + d.error);
278
+ }}
279
+ }})
280
+ .catch(e => alert('Error: ' + e));
281
  }}
282
 
283
+ function launchAgents() {{
284
+ fetch('/launch-agents', {{ method: 'POST' }})
285
+ .then(r => r.json())
286
+ .then(d => {{
287
+ if (d.success) {{
288
+ alert('✅ Antigravity Agents launched!\\n\\n' + d.message);
289
+ }} else {{
290
+ alert('❌ Error: ' + d.error);
 
 
 
291
  }}
292
+ }})
293
+ .catch(e => alert('Error: ' + e));
294
+ }}
295
+
296
+ function launchChat() {{
297
+ fetch('/launch-chat', {{ method: 'POST' }})
298
+ .then(r => r.json())
299
+ .then(d => {{
300
+ if (d.success) {{
301
+ alert('✅ AI Chat launched!\\n\\n' + d.message);
302
+ }} else {{
303
+ alert('❌ Error: ' + d.error);
 
 
 
 
304
  }}
305
+ }})
306
+ .catch(e => alert('Error: ' + e));
307
+ }}
308
  </script>
309
  </body>
310
  </html>
 
346
  print(f"[Antigravity VS Code] {format % args}")
347
 
348
  def do_POST(self):
349
+ global vscode_process
350
+
351
+ if self.path == '/launch-ide':
352
+ self.send_response(200)
353
+ self.send_header('Content-type', 'application/json')
354
+ self.end_headers()
355
+
356
+ try:
357
+ # Launch Antigravity VS Code web interface
358
+ if vscode_process is None or vscode_process.poll() is not None:
359
+ vscode_process = subprocess.Popen(
360
+ ['antigravity', '--serve-web'],
361
+ stdout=subprocess.PIPE,
362
+ stderr=subprocess.PIPE
363
+ )
364
+ time.sleep(2)
365
+
366
+ response = {
367
+ 'success': True,
368
+ 'message': 'Antigravity VS Code IDE launched on http://localhost:8000'
369
+ }
370
+ except Exception as e:
371
+ response = {
372
+ 'success': False,
373
+ 'error': str(e)
374
+ }
375
 
376
+ self.wfile.write(json.dumps(response).encode())
377
+
378
+ elif self.path == '/launch-agents':
379
+ self.send_response(200)
380
+ self.send_header('Content-type', 'application/json')
381
+ self.end_headers()
382
 
383
  try:
384
+ result = subprocess.run(['antigravity', 'agents'],
385
+ capture_output=True, text=True, timeout=3)
386
+ response = {
387
+ 'success': True,
388
+ 'message': 'Antigravity Agents activated!\n' + result.stdout
389
+ }
390
  except Exception as e:
391
+ response = {
392
+ 'success': False,
393
+ 'error': str(e)
394
+ }
395
 
396
+ self.wfile.write(json.dumps(response).encode())
397
+
398
+ elif self.path == '/launch-chat':
399
  self.send_response(200)
400
  self.send_header('Content-type', 'application/json')
401
  self.end_headers()
402
 
403
+ try:
404
+ result = subprocess.run(['antigravity', 'chat'],
405
+ capture_output=True, text=True, timeout=3)
406
+ response = {
407
+ 'success': True,
408
+ 'message': 'AI Chat opened!\n' + result.stdout
409
+ }
410
+ except Exception as e:
411
+ response = {
412
+ 'success': False,
413
+ 'error': str(e)
414
+ }
415
+
416
  self.wfile.write(json.dumps(response).encode())
417
+
418
  else:
419
  self.send_response(404)
420
  self.end_headers()