Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,9 @@ import subprocess
|
|
| 9 |
import sys
|
| 10 |
import os
|
| 11 |
import json
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
class AntigravityHandler(BaseHTTPRequestHandler):
|
| 14 |
def do_GET(self):
|
|
@@ -166,6 +169,42 @@ class AntigravityHandler(BaseHTTPRequestHandler):
|
|
| 166 |
margin: 10px 0;
|
| 167 |
border: 2px solid #1f6feb;
|
| 168 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
</style>
|
| 170 |
</head>
|
| 171 |
<body>
|
|
@@ -237,12 +276,60 @@ antigravity --install-extension ext-id # Install extension</div>
|
|
| 237 |
<li><strong>Development Tools:</strong> Complete development environment</li>
|
| 238 |
</ul>
|
| 239 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
</div>
|
| 241 |
|
| 242 |
<script>
|
| 243 |
function showVersion() {{
|
| 244 |
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');
|
| 245 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
</script>
|
| 247 |
</body>
|
| 248 |
</html>
|
|
@@ -283,6 +370,42 @@ antigravity --install-extension ext-id # Install extension</div>
|
|
| 283 |
def log_message(self, format, *args):
|
| 284 |
print(f"[Antigravity VS Code] {format % args}")
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
def main():
|
| 287 |
port = int(os.environ.get('PORT', 7860))
|
| 288 |
server = HTTPServer(('0.0.0.0', port), AntigravityHandler)
|
|
|
|
| 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):
|
|
|
|
| 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>
|
|
|
|
| 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 print('Hello, World!') # 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, '<').replace(/>/g, '>');
|
| 326 |
+
outputDiv.className = outputClass;
|
| 327 |
+
}} catch (err) {{
|
| 328 |
+
alert('Error: ' + err.message);
|
| 329 |
+
}}
|
| 330 |
+
}});
|
| 331 |
+
}}
|
| 332 |
+
}});
|
| 333 |
</script>
|
| 334 |
</body>
|
| 335 |
</html>
|
|
|
|
| 370 |
def log_message(self, format, *args):
|
| 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()
|
| 408 |
+
|
| 409 |
def main():
|
| 410 |
port = int(os.environ.get('PORT', 7860))
|
| 411 |
server = HTTPServer(('0.0.0.0', port), AntigravityHandler)
|