theguywhosucks commited on
Commit
a36cfb6
·
verified ·
1 Parent(s): 12e19da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -591
app.py CHANGED
@@ -1,8 +1,6 @@
1
  import gradio as gr
2
  from gradio_client import Client
3
  import json
4
- import time
5
- import threading
6
  import random
7
  from datetime import datetime
8
 
@@ -17,10 +15,8 @@ class SandboxManager:
17
  self.client = None
18
  self.current_engine = None
19
  self.is_connected = False
20
- self.last_status = "Disconnected"
21
 
22
  def select_random_engine(self):
23
- """Randomly select an engine"""
24
  self.current_engine = random.choice(BACKEND_ENGINES)
25
  return self.current_engine
26
 
@@ -38,7 +34,6 @@ class SandboxManager:
38
  def launch_sandbox(self, main_py_code, requirements_txt):
39
  if not self.is_connected:
40
  return "✗ Not connected to backend. Please connect first.", ""
41
-
42
  try:
43
  result = self.client.predict(
44
  code=main_py_code,
@@ -52,7 +47,6 @@ class SandboxManager:
52
  def fetch_logs(self):
53
  if not self.is_connected:
54
  return "✗ Not connected to backend"
55
-
56
  try:
57
  result = self.client.predict(api_name="/fetch_logs")
58
  timestamp = datetime.now().strftime("%H:%M:%S")
@@ -63,7 +57,6 @@ class SandboxManager:
63
  def kill_sandbox(self):
64
  if not self.is_connected:
65
  return "✗ Not connected to backend", ""
66
-
67
  try:
68
  result = self.client.predict(api_name="/kill_sandbox")
69
  return f"✓ Sandbox terminated on {self.current_engine}\n\nResponse: {result}", self.get_status()
@@ -73,7 +66,6 @@ class SandboxManager:
73
  def get_status(self):
74
  if not self.is_connected:
75
  return "OFFLINE"
76
-
77
  try:
78
  result = self.client.predict(api_name="/status_sandbox")
79
  if "running" in str(result).lower():
@@ -86,650 +78,135 @@ class SandboxManager:
86
  # Initialize sandbox manager
87
  sandbox = SandboxManager()
88
 
89
- # Professional code templates
90
- SAMPLE_MAIN_PY = """#!/usr/bin/env python3
91
- \"\"\"
92
- Sandbox Compute Environment
93
- Enterprise Python Application Template
94
- \"\"\"
95
-
96
- import os
97
- import sys
98
- import json
99
- import logging
100
- from datetime import datetime, timezone
101
-
102
- # Configure logging
103
- logging.basicConfig(
104
- level=logging.INFO,
105
- format='%(asctime)s - %(levelname)s - %(message)s'
106
- )
107
- logger = logging.getLogger(__name__)
108
-
109
- def initialize_environment():
110
- \"\"\"Initialize the compute environment\"\"\"
111
- logger.info("Initializing sandbox environment...")
112
-
113
- env_info = {
114
- "timestamp": datetime.now(timezone.utc).isoformat(),
115
- "python_version": sys.version,
116
- "platform": os.name,
117
- "working_directory": os.getcwd(),
118
- "environment_variables": dict(os.environ)
119
- }
120
-
121
- logger.info(f"Environment initialized: {env_info['timestamp']}")
122
- return env_info
123
-
124
- def execute_business_logic():
125
- \"\"\"Main application business logic\"\"\"
126
- logger.info("Executing main application logic...")
127
-
128
- # Example: Data processing pipeline
129
- data_points = list(range(1, 101))
130
- processed_data = [x ** 2 for x in data_points if x % 2 == 0]
131
-
132
- result = {
133
- "status": "success",
134
- "data_points_processed": len(processed_data),
135
- "sum_of_squares": sum(processed_data),
136
- "processing_time": datetime.now(timezone.utc).isoformat()
137
- }
138
-
139
- logger.info(f"Processing complete: {result}")
140
- return result
141
-
142
- def main():
143
- \"\"\"Main application entry point\"\"\"
144
- try:
145
- print("=" * 60)
146
- print("SANDBOX COMPUTE ENVIRONMENT - PRODUCTION RUNTIME")
147
- print("=" * 60)
148
-
149
- # Initialize
150
- env_info = initialize_environment()
151
- print(f"Environment: {env_info['platform']}")
152
- print(f"Python: {env_info['python_version'].split()[0]}")
153
- print(f"Started: {env_info['timestamp']}")
154
-
155
- print("\\n" + "-" * 40)
156
- print("EXECUTING APPLICATION LOGIC")
157
- print("-" * 40)
158
-
159
- # Execute business logic
160
- result = execute_business_logic()
161
-
162
- # Output results
163
- print(f"\\nStatus: {result['status'].upper()}")
164
- print(f"Data Points: {result['data_points_processed']}")
165
- print(f"Computation Result: {result['sum_of_squares']}")
166
- print(f"Completed: {result['processing_time']}")
167
-
168
- print("\\n" + "=" * 60)
169
- print("APPLICATION EXECUTION COMPLETED SUCCESSFULLY")
170
- print("=" * 60)
171
-
172
- except Exception as e:
173
- logger.error(f"Application failed: {str(e)}")
174
- raise
175
-
176
- if __name__ == "__main__":
177
- main()
178
- """
179
-
180
- SAMPLE_REQUIREMENTS_TXT = """# Enterprise Python Dependencies
181
- # Production-grade package specifications
182
-
183
- # Core utilities and date handling
184
- requests>=2.31.0,<3.0.0
185
- python-dateutil>=2.8.2,<3.0.0
186
- pytz>=2023.3
187
-
188
- # Data processing and analysis
189
- numpy>=1.24.0,<2.0.0
190
- pandas>=2.0.0,<3.0.0
191
-
192
- # Logging and monitoring
193
- structlog>=23.1.0
194
- prometheus-client>=0.17.0
195
-
196
- # Configuration management
197
- pydantic>=2.0.0,<3.0.0
198
- python-dotenv>=1.0.0
199
-
200
- # Database connectivity (uncomment as needed)
201
- # sqlalchemy>=2.0.0,<3.0.0
202
- # psycopg2-binary>=2.9.0
203
- # redis>=4.5.0
204
-
205
- # Web frameworks (uncomment as needed)
206
- # fastapi>=0.100.0,<1.0.0
207
- # uvicorn[standard]>=0.23.0
208
- # gunicorn>=21.0.0
209
 
210
- # Scientific computing (uncomment as needed)
211
- # scipy>=1.11.0,<2.0.0
212
- # scikit-learn>=1.3.0,<2.0.0
213
- # matplotlib>=3.7.0,<4.0.0
214
-
215
- # Development and testing (uncomment as needed)
216
- # pytest>=7.4.0,<8.0.0
217
- # black>=23.0.0,<24.0.0
218
- # mypy>=1.5.0,<2.0.0
219
- # flake8>=6.0.0,<7.0.0
220
- """
221
-
222
- # Professional industrial CSS
223
- professional_css = """
224
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
225
 
226
  :root {
227
- --primary-color: #2563eb;
228
- --primary-hover: #1d4ed8;
229
- --secondary-color: #64748b;
230
- --success-color: #059669;
231
- --warning-color: #d97706;
232
- --danger-color: #dc2626;
233
- --background: #f8fafc;
234
  --surface: #ffffff;
235
- --border: #e2e8f0;
236
- --text-primary: #1e293b;
237
- --text-secondary: #64748b;
238
- --text-muted: #94a3b8;
239
- }
240
-
241
- .gradio-container {
242
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
243
- background-color: var(--background) !important;
244
- color: var(--text-primary) !important;
245
- min-height: 100vh;
246
- line-height: 1.5;
247
- }
248
-
249
- /* Professional Header */
250
- .platform-header {
251
- background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
252
- color: white !important;
253
- padding: 16px 24px !important;
254
- border-bottom: 3px solid var(--primary-color) !important;
255
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
256
- }
257
-
258
- .platform-title {
259
- font-size: 24px !important;
260
- font-weight: 700 !important;
261
- letter-spacing: -0.025em !important;
262
- }
263
-
264
- .platform-subtitle {
265
- font-size: 14px !important;
266
- opacity: 0.8 !important;
267
- margin-top: 4px !important;
268
- }
269
-
270
- /* Navigation */
271
- .nav-breadcrumb {
272
- background-color: #f1f5f9 !important;
273
- padding: 12px 24px !important;
274
- font-size: 13px !important;
275
- color: var(--text-secondary) !important;
276
- border-bottom: 1px solid var(--border) !important;
277
- }
278
-
279
- /* Container System */
280
- .enterprise-container {
281
- background-color: var(--surface) !important;
282
- border: 1px solid var(--border) !important;
283
- border-radius: 12px !important;
284
- margin: 20px !important;
285
- overflow: hidden !important;
286
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06) !important;
287
- }
288
-
289
- .container-header {
290
- background: linear-gradient(to right, #f8fafc, #f1f5f9) !important;
291
- border-bottom: 1px solid var(--border) !important;
292
- padding: 16px 24px !important;
293
- font-weight: 600 !important;
294
- font-size: 16px !important;
295
- color: var(--text-primary) !important;
296
- display: flex !important;
297
- align-items: center !important;
298
- gap: 8px !important;
299
- }
300
-
301
- .container-content {
302
- padding: 24px !important;
303
- }
304
-
305
- /* Professional Buttons */
306
- .btn-primary {
307
- background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%) !important;
308
- color: white !important;
309
- border: none !important;
310
- border-radius: 8px !important;
311
- padding: 12px 24px !important;
312
- font-size: 14px !important;
313
- font-weight: 500 !important;
314
- transition: all 0.2s ease !important;
315
- box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2) !important;
316
- }
317
-
318
- .btn-primary:hover {
319
- transform: translateY(-1px) !important;
320
- box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3) !important;
321
- }
322
-
323
- .btn-secondary {
324
- background-color: var(--surface) !important;
325
- color: var(--text-primary) !important;
326
- border: 1px solid var(--border) !important;
327
- border-radius: 8px !important;
328
- padding: 12px 24px !important;
329
- font-size: 14px !important;
330
- font-weight: 500 !important;
331
- transition: all 0.2s ease !important;
332
- }
333
-
334
- .btn-secondary:hover {
335
- background-color: #f8fafc !important;
336
- border-color: var(--secondary-color) !important;
337
- }
338
-
339
- .btn-danger {
340
- background: linear-gradient(135deg, var(--danger-color) 0%, #b91c1c 100%) !important;
341
- color: white !important;
342
- border: none !important;
343
- border-radius: 8px !important;
344
- padding: 12px 24px !important;
345
- font-size: 14px !important;
346
- font-weight: 500 !important;
347
- transition: all 0.2s ease !important;
348
- box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2) !important;
349
  }
350
 
351
- /* Status Indicators */
352
- .status-online {
353
- background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%) !important;
354
- color: var(--success-color) !important;
355
- border: 1px solid #86efac !important;
356
- border-radius: 8px !important;
357
- padding: 16px !important;
358
- font-weight: 600 !important;
359
- text-align: center !important;
360
- }
361
-
362
- .status-offline {
363
- background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%) !important;
364
- color: var(--danger-color) !important;
365
- border: 1px solid #fca5a5 !important;
366
- border-radius: 8px !important;
367
- padding: 16px !important;
368
- font-weight: 600 !important;
369
- text-align: center !important;
370
- }
371
-
372
- .status-warning {
373
- background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%) !important;
374
- color: var(--warning-color) !important;
375
- border: 1px solid #fde68a !important;
376
- border-radius: 8px !important;
377
- padding: 16px !important;
378
- font-weight: 600 !important;
379
- text-align: center !important;
380
- }
381
-
382
- /* Code Editor */
383
- .code-editor-professional {
384
- font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', monospace !important;
385
- background: #1e1e1e !important;
386
- border: 2px solid var(--border) !important;
387
- border-radius: 8px !important;
388
- font-size: 14px !important;
389
- line-height: 1.5 !important;
390
- box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06) !important;
391
- }
392
-
393
- .requirements-editor {
394
- font-family: 'JetBrains Mono', monospace !important;
395
- background: #2d2d2d !important;
396
- border: 2px solid var(--border) !important;
397
- border-radius: 8px !important;
398
- font-size: 13px !important;
399
- line-height: 1.4 !important;
400
- }
401
-
402
- /* Logs Terminal */
403
- .terminal-logs {
404
- font-family: 'JetBrains Mono', monospace !important;
405
- background: #0f172a !important;
406
- color: #e2e8f0 !important;
407
- border: 2px solid #334155 !important;
408
- border-radius: 8px !important;
409
- font-size: 13px !important;
410
- line-height: 1.6 !important;
411
- padding: 16px !important;
412
- }
413
-
414
- /* Sidebar */
415
- .monitoring-panel {
416
- background-color: var(--surface) !important;
417
- border: 1px solid var(--border) !important;
418
- border-radius: 12px !important;
419
- overflow: hidden !important;
420
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1) !important;
421
- height: fit-content !important;
422
- }
423
-
424
- .panel-header {
425
- background: linear-gradient(to right, #f1f5f9, #e2e8f0) !important;
426
- padding: 12px 16px !important;
427
- font-weight: 600 !important;
428
- font-size: 14px !important;
429
- color: var(--text-primary) !important;
430
- border-bottom: 1px solid var(--border) !important;
431
- }
432
 
433
- .panel-content {
434
- padding: 16px !important;
435
- }
436
-
437
- /* Form Elements */
438
- .form-group {
439
- margin-bottom: 20px !important;
440
- }
441
 
442
- .form-label {
443
- font-size: 14px !important;
444
- font-weight: 500 !important;
445
- color: var(--text-primary) !important;
446
- margin-bottom: 6px !important;
447
- display: block !important;
448
- }
449
 
450
- .info-badge {
451
- background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%) !important;
452
- color: var(--primary-color) !important;
453
- border: 1px solid #93c5fd !important;
454
- border-radius: 6px !important;
455
- padding: 12px 16px !important;
456
- font-size: 13px !important;
457
- font-weight: 500 !important;
458
- }
459
 
460
- /* Metrics */
461
- .metric-card {
462
- text-align: center !important;
463
- padding: 16px !important;
464
- border-right: 1px solid var(--border) !important;
465
- }
466
 
467
- .metric-card:last-child {
468
- border-right: none !important;
469
- }
470
 
471
- .metric-value {
472
- font-size: 28px !important;
473
- font-weight: 700 !important;
474
- color: var(--primary-color) !important;
475
- line-height: 1 !important;
476
- }
477
 
478
- .metric-label {
479
- font-size: 12px !important;
480
- color: var(--text-secondary) !important;
481
- margin-top: 4px !important;
482
- font-weight: 500 !important;
483
- text-transform: uppercase !important;
484
- letter-spacing: 0.025em !important;
485
- }
486
-
487
- /* Professional spacing */
488
- .section-divider {
489
- height: 1px !important;
490
- background: var(--border) !important;
491
- margin: 24px 0 !important;
492
- }
493
-
494
- .mb-4 {
495
- margin-bottom: 16px !important;
496
- }
497
-
498
- .mt-4 {
499
- margin-top: 16px !important;
500
- }
501
  """
502
 
503
- def auto_refresh_status():
504
- return sandbox.get_status()
 
505
 
506
- def auto_refresh_logs():
507
- return sandbox.fetch_logs()
508
-
509
- def load_sample_files():
510
- """Load professional sample files"""
511
- return SAMPLE_MAIN_PY, SAMPLE_REQUIREMENTS_TXT
512
-
513
- # Build the professional interface
514
- with gr.Blocks(css=professional_css, title="Sandbox Compute Platform", theme=gr.themes.Default()) as demo:
515
-
516
- # Platform Header
517
  gr.HTML("""
518
  <div class="platform-header">
519
  <div class="platform-title">Sandbox Compute Platform</div>
520
  <div class="platform-subtitle">Enterprise-grade cloud computing infrastructure</div>
521
  </div>
522
  <div class="nav-breadcrumb">
523
- Dashboard → Compute Services → Sandbox Management Console
524
  </div>
525
  """)
526
-
527
  with gr.Row():
528
- # Main Content Area
529
  with gr.Column(scale=3):
530
- # Infrastructure Management
531
  with gr.Group(elem_classes=["enterprise-container"]):
532
  gr.HTML('<div class="container-header">🔧 Infrastructure Management</div>')
533
  with gr.Group(elem_classes=["container-content"]):
534
  with gr.Row():
535
  connect_btn = gr.Button("Initialize Connection", elem_classes=["btn-primary"])
536
  load_samples_btn = gr.Button("Load Templates", elem_classes=["btn-secondary"])
537
-
538
  gr.HTML('<div class="form-label mt-4">Active Compute Engine</div>')
539
- current_engine_display = gr.Textbox(
540
- value="No engine selected",
541
- interactive=False,
542
- elem_classes=["info-badge"],
543
- show_label=False
544
- )
545
-
546
  gr.HTML('<div class="form-label mt-4">Connection Status</div>')
547
- connection_status = gr.Textbox(
548
- value="DISCONNECTED",
549
- interactive=False,
550
- elem_classes=["status-offline"],
551
- show_label=False
552
- )
553
-
554
- # Development Environment
555
  with gr.Group(elem_classes=["enterprise-container"]):
556
  gr.HTML('<div class="container-header">💻 Development Environment</div>')
557
  with gr.Group(elem_classes=["container-content"]):
558
  with gr.Tab("main.py"):
559
  gr.HTML('<div class="form-label">Application Source Code</div>')
560
- main_py_editor = gr.Code(
561
- value="# Enterprise Python Application\nprint('Sandbox Compute Platform - Ready')",
562
- language="python",
563
- lines=20,
564
- elem_classes=["code-editor-professional"],
565
- show_label=False
566
- )
567
-
568
  with gr.Tab("requirements.txt"):
569
  gr.HTML('<div class="form-label">Dependency Specifications</div>')
570
- requirements_editor = gr.Textbox(
571
- value="# Production dependencies\n# Specify exact versions for reproducibility",
572
- lines=20,
573
- elem_classes=["requirements-editor"],
574
- show_label=False,
575
- max_lines=25
576
- )
577
-
578
- # Deployment Controls
579
  gr.HTML('<div class="section-divider"></div>')
580
  with gr.Row():
581
  launch_btn = gr.Button("Deploy Application", elem_classes=["btn-primary"], size="lg")
582
  kill_btn = gr.Button("Terminate Instance", elem_classes=["btn-danger"], size="lg")
583
-
584
  gr.HTML('<div class="form-label mt-4">Deployment Output</div>')
585
- launch_output = gr.Textbox(
586
- lines=6,
587
- interactive=False,
588
- placeholder="Deployment logs and status information will appear here...",
589
- elem_classes=["terminal-logs"],
590
- show_label=False
591
- )
592
-
593
  # Monitoring Panel
594
  with gr.Column(scale=1):
595
- # System Status
596
  with gr.Group(elem_classes=["monitoring-panel"]):
597
  gr.HTML('<div class="panel-header">📊 System Monitor</div>')
598
  with gr.Group(elem_classes=["panel-content"]):
599
  gr.HTML('<div class="form-label">Instance Status</div>')
600
- status_display = gr.Textbox(
601
- value="OFFLINE",
602
- interactive=False,
603
- elem_classes=["status-offline"],
604
- show_label=False
605
- )
606
-
607
  status_refresh_btn = gr.Button("Refresh Status", elem_classes=["btn-secondary"], size="sm")
608
-
609
  gr.HTML('<div class="section-divider"></div>')
610
-
611
  gr.HTML('<div class="form-label">Monitoring Settings</div>')
612
- auto_refresh_status_cb = gr.Checkbox(
613
- label="Auto-refresh status (5s interval)",
614
- value=False
615
- )
616
- auto_refresh_logs_cb = gr.Checkbox(
617
- label="Auto-refresh logs (10s interval)",
618
- value=False
619
- )
620
-
621
- # System Metrics
622
- with gr.Group(elem_classes=["monitoring-panel"]):
623
- gr.HTML('<div class="panel-header">📈 Performance Metrics</div>')
624
- gr.HTML('''
625
- <div style="padding: 16px;">
626
- <div class="metric-card">
627
- <div class="metric-value">--</div>
628
- <div class="metric-label">CPU Usage</div>
629
- </div>
630
- <div class="metric-card">
631
- <div class="metric-value">--</div>
632
- <div class="metric-label">Memory</div>
633
- </div>
634
- <div class="metric-card">
635
- <div class="metric-value">--</div>
636
- <div class="metric-label">Uptime</div>
637
- </div>
638
- </div>
639
- ''')
640
-
641
- # System Logs
642
  with gr.Group(elem_classes=["enterprise-container"]):
643
  gr.HTML('<div class="container-header">📋 System Logs</div>')
644
  with gr.Group(elem_classes=["container-content"]):
645
  with gr.Row():
646
  fetch_logs_btn = gr.Button("Fetch Application Logs", elem_classes=["btn-secondary"])
647
  gr.HTML('<div style="flex-grow: 1;"></div>')
648
-
649
  gr.HTML('<div class="form-label mt-4">Runtime Logs</div>')
650
- logs_display = gr.Textbox(
651
- lines=14,
652
- interactive=False,
653
- elem_classes=["terminal-logs"],
654
- placeholder="[SYSTEM] Application logs will be displayed here...\n[INFO] Logs are captured in real-time from your running application\n[DEBUG] Use 'Fetch Application Logs' to retrieve the latest output",
655
- show_label=False
656
- )
657
-
658
- # Event Handlers
659
- connect_btn.click(
660
- fn=sandbox.connect,
661
- outputs=[connection_status, current_engine_display]
662
- )
663
-
664
- load_samples_btn.click(
665
- fn=load_sample_files,
666
- outputs=[main_py_editor, requirements_editor]
667
- )
668
-
669
- launch_btn.click(
670
- fn=sandbox.launch_sandbox,
671
- inputs=[main_py_editor, requirements_editor],
672
- outputs=[launch_output, status_display]
673
- )
674
-
675
- kill_btn.click(
676
- fn=sandbox.kill_sandbox,
677
- outputs=[launch_output, status_display]
678
- )
679
-
680
- status_refresh_btn.click(
681
- fn=sandbox.get_status,
682
- outputs=[status_display]
683
- )
684
-
685
- fetch_logs_btn.click(
686
- fn=sandbox.fetch_logs,
687
- outputs=[logs_display]
688
- )
689
-
690
- # Auto-refresh Timers
691
- status_timer = gr.Timer(5)
692
- logs_timer = gr.Timer(10)
693
-
694
- status_timer.tick(
695
- fn=auto_refresh_status,
696
- outputs=[status_display],
697
- show_progress=False
698
- )
699
-
700
- logs_timer.tick(
701
- fn=auto_refresh_logs,
702
- outputs=[logs_display],
703
- show_progress=False
704
- )
705
-
706
- # Timer Controls
707
- auto_refresh_status_cb.change(
708
- lambda enabled: gr.Timer(5 if enabled else None),
709
- inputs=[auto_refresh_status_cb],
710
- outputs=[status_timer]
711
- )
712
-
713
- auto_refresh_logs_cb.change(
714
- lambda enabled: gr.Timer(10 if enabled else None),
715
- inputs=[auto_refresh_logs_cb],
716
- outputs=[logs_timer]
717
- )
718
 
719
- # Professional Footer
720
- gr.HTML("""
721
- <div style="text-align: center; margin-top: 40px; padding: 24px; background: linear-gradient(to right, #f8fafc, #f1f5f9); border-top: 1px solid #e2e8f0; color: #64748b; font-size: 13px;">
722
- <p style="font-weight: 500; margin-bottom: 8px;">Sandbox Compute Platform</p>
723
- <p style="font-size: 12px; margin-top: 12px; opacity: 0.8;">
724
- Runtime Engines: SANDBOXBACKEND2, SANDBOX_BACKEND
725
- </p>
726
- </div>
727
- """)
728
-
729
- if __name__ == "__main__":
730
- demo.launch(
731
- share=True,
732
- server_name="0.0.0.0",
733
- server_port=7860,
734
- show_error=True
735
- )
 
1
  import gradio as gr
2
  from gradio_client import Client
3
  import json
 
 
4
  import random
5
  from datetime import datetime
6
 
 
15
  self.client = None
16
  self.current_engine = None
17
  self.is_connected = False
 
18
 
19
  def select_random_engine(self):
 
20
  self.current_engine = random.choice(BACKEND_ENGINES)
21
  return self.current_engine
22
 
 
34
  def launch_sandbox(self, main_py_code, requirements_txt):
35
  if not self.is_connected:
36
  return "✗ Not connected to backend. Please connect first.", ""
 
37
  try:
38
  result = self.client.predict(
39
  code=main_py_code,
 
47
  def fetch_logs(self):
48
  if not self.is_connected:
49
  return "✗ Not connected to backend"
 
50
  try:
51
  result = self.client.predict(api_name="/fetch_logs")
52
  timestamp = datetime.now().strftime("%H:%M:%S")
 
57
  def kill_sandbox(self):
58
  if not self.is_connected:
59
  return "✗ Not connected to backend", ""
 
60
  try:
61
  result = self.client.predict(api_name="/kill_sandbox")
62
  return f"✓ Sandbox terminated on {self.current_engine}\n\nResponse: {result}", self.get_status()
 
66
  def get_status(self):
67
  if not self.is_connected:
68
  return "OFFLINE"
 
69
  try:
70
  result = self.client.predict(api_name="/status_sandbox")
71
  if "running" in str(result).lower():
 
78
  # Initialize sandbox manager
79
  sandbox = SandboxManager()
80
 
81
+ # Sample files
82
+ SAMPLE_MAIN_PY = "# Enterprise Python Application\nprint('Sandbox Compute Platform - Ready')"
83
+ SAMPLE_REQUIREMENTS_TXT = "# Production dependencies\n# Specify exact versions for reproducibility"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
+ # Industrial-grade CSS
86
+ industrial_css = """
 
 
 
 
 
 
 
 
 
 
 
 
87
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
88
 
89
  :root {
90
+ --primary-color: #1f2937;
91
+ --primary-hover: #111827;
92
+ --secondary-color: #4b5563;
93
+ --success-color: #10b981;
94
+ --warning-color: #f59e0b;
95
+ --danger-color: #ef4444;
96
+ --background: #f3f4f6;
97
  --surface: #ffffff;
98
+ --border: #d1d5db;
99
+ --text-primary: #111827;
100
+ --text-secondary: #6b7280;
101
+ --text-muted: #9ca3af;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
103
 
104
+ .gradio-container { font-family: 'Inter', sans-serif !important; background-color: var(--background) !important; min-height: 100vh; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
+ .platform-header { background: linear-gradient(90deg, var(--primary-color), var(--primary-hover)) !important; color: #f9fafb !important; padding: 20px 32px !important; border-bottom: 4px solid var(--primary-color); box-shadow: 0 6px 12px rgba(0,0,0,0.15); }
107
+ .platform-title { font-size: 26px !important; font-weight: 700 !important; }
108
+ .platform-subtitle { font-size: 14px !important; opacity: 0.85 !important; margin-top: 4px !important; }
 
 
 
 
 
109
 
110
+ .nav-breadcrumb { background-color: #e5e7eb !important; padding: 12px 24px !important; font-size: 13px !important; color: var(--text-secondary) !important; border-bottom: 1px solid var(--border) !important; border-radius: 6px !important; margin-top: 8px !important; }
 
 
 
 
 
 
111
 
112
+ .enterprise-container { background-color: var(--surface) !important; border: 1px solid var(--border) !important; border-radius: 12px !important; margin: 16px 0 !important; overflow: hidden !important; box-shadow: 0 2px 6px rgba(0,0,0,0.06) !important; }
113
+ .container-header { background: linear-gradient(to right, #f9fafb, #f3f4f6) !important; border-bottom: 1px solid var(--border) !important; padding: 14px 24px !important; font-weight: 600 !important; font-size: 16px !important; display: flex !important; align-items: center; gap: 8px !important; }
114
+ .container-content { padding: 20px !important; }
 
 
 
 
 
 
115
 
116
+ .btn-primary { background: linear-gradient(135deg, var(--primary-color), var(--primary-hover)) !important; color: #fff !important; border-radius: 6px !important; padding: 10px 24px !important; font-weight: 500 !important; transition: all 0.2s ease !important; }
117
+ .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,0,0,0.15) !important; }
118
+ .btn-secondary { background-color: var(--surface) !important; border: 1px solid var(--border) !important; color: var(--text-primary) !important; border-radius: 6px !important; padding: 10px 24px !important; }
119
+ .btn-secondary:hover { background-color: #f9fafb !important; border-color: var(--secondary-color) !important; }
120
+ .btn-danger { background: linear-gradient(135deg, var(--danger-color), #b91c1c) !important; color: #fff !important; border-radius: 6px !important; padding: 10px 24px !important; }
 
121
 
122
+ .status-online { background: #d1fae5 !important; color: var(--success-color) !important; }
123
+ .status-offline { background: #fee2e2 !important; color: var(--danger-color) !important; }
124
+ .status-warning { background: #fef3c7 !important; color: var(--warning-color) !important; }
125
 
126
+ .code-editor-professional { font-family: 'JetBrains Mono', monospace !important; background: #1f2937 !important; color: #f3f4f6 !important; border-radius: 8px !important; padding: 12px !important; }
127
+ .requirements-editor { font-family: 'JetBrains Mono', monospace !important; background: #27272a !important; color: #f3f4f6 !important; border-radius: 8px !important; padding: 10px !important; }
128
+ .terminal-logs { font-family: 'JetBrains Mono', monospace !important; background: #0f172a !important; color: #e2e8f0 !important; border-radius: 8px !important; padding: 14px !important; }
 
 
 
129
 
130
+ .monitoring-panel { border-radius: 12px !important; padding: 0 !important; margin: 16px 0 !important; box-shadow: 0 2px 4px rgba(0,0,0,0.06) !important; }
131
+ .panel-header { padding: 12px 16px !important; font-weight: 600 !important; background: #f3f4f6; border-bottom: 1px solid var(--border) !important; }
132
+ .panel-content { padding: 16px !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  """
134
 
135
+ def auto_refresh_status(): return sandbox.get_status()
136
+ def auto_refresh_logs(): return sandbox.fetch_logs()
137
+ def load_sample_files(): return SAMPLE_MAIN_PY, SAMPLE_REQUIREMENTS_TXT
138
 
139
+ # Build Gradio interface
140
+ with gr.Blocks(css=industrial_css, title="Sandbox Compute Platform") as demo:
 
 
 
 
 
 
 
 
 
141
  gr.HTML("""
142
  <div class="platform-header">
143
  <div class="platform-title">Sandbox Compute Platform</div>
144
  <div class="platform-subtitle">Enterprise-grade cloud computing infrastructure</div>
145
  </div>
146
  <div class="nav-breadcrumb">
147
+ Sandbox Management Console
148
  </div>
149
  """)
150
+
151
  with gr.Row():
152
+ # Main Content
153
  with gr.Column(scale=3):
 
154
  with gr.Group(elem_classes=["enterprise-container"]):
155
  gr.HTML('<div class="container-header">🔧 Infrastructure Management</div>')
156
  with gr.Group(elem_classes=["container-content"]):
157
  with gr.Row():
158
  connect_btn = gr.Button("Initialize Connection", elem_classes=["btn-primary"])
159
  load_samples_btn = gr.Button("Load Templates", elem_classes=["btn-secondary"])
 
160
  gr.HTML('<div class="form-label mt-4">Active Compute Engine</div>')
161
+ current_engine_display = gr.Textbox(value="No engine selected", interactive=False, elem_classes=["info-badge"], show_label=False)
 
 
 
 
 
 
162
  gr.HTML('<div class="form-label mt-4">Connection Status</div>')
163
+ connection_status = gr.Textbox(value="DISCONNECTED", interactive=False, elem_classes=["status-offline"], show_label=False)
164
+
 
 
 
 
 
 
165
  with gr.Group(elem_classes=["enterprise-container"]):
166
  gr.HTML('<div class="container-header">💻 Development Environment</div>')
167
  with gr.Group(elem_classes=["container-content"]):
168
  with gr.Tab("main.py"):
169
  gr.HTML('<div class="form-label">Application Source Code</div>')
170
+ main_py_editor = gr.Code(value=SAMPLE_MAIN_PY, language="python", lines=20, elem_classes=["code-editor-professional"], show_label=False)
 
 
 
 
 
 
 
171
  with gr.Tab("requirements.txt"):
172
  gr.HTML('<div class="form-label">Dependency Specifications</div>')
173
+ requirements_editor = gr.Textbox(value=SAMPLE_REQUIREMENTS_TXT, lines=20, elem_classes=["requirements-editor"], show_label=False, max_lines=25)
 
 
 
 
 
 
 
 
174
  gr.HTML('<div class="section-divider"></div>')
175
  with gr.Row():
176
  launch_btn = gr.Button("Deploy Application", elem_classes=["btn-primary"], size="lg")
177
  kill_btn = gr.Button("Terminate Instance", elem_classes=["btn-danger"], size="lg")
 
178
  gr.HTML('<div class="form-label mt-4">Deployment Output</div>')
179
+ launch_output = gr.Textbox(lines=6, interactive=False, placeholder="Deployment logs and status information will appear here...", elem_classes=["terminal-logs"], show_label=False)
180
+
 
 
 
 
 
 
181
  # Monitoring Panel
182
  with gr.Column(scale=1):
 
183
  with gr.Group(elem_classes=["monitoring-panel"]):
184
  gr.HTML('<div class="panel-header">📊 System Monitor</div>')
185
  with gr.Group(elem_classes=["panel-content"]):
186
  gr.HTML('<div class="form-label">Instance Status</div>')
187
+ status_display = gr.Textbox(value="OFFLINE", interactive=False, elem_classes=["status-offline"], show_label=False)
 
 
 
 
 
 
188
  status_refresh_btn = gr.Button("Refresh Status", elem_classes=["btn-secondary"], size="sm")
 
189
  gr.HTML('<div class="section-divider"></div>')
 
190
  gr.HTML('<div class="form-label">Monitoring Settings</div>')
191
+ auto_refresh_status_cb = gr.Checkbox(label="Auto-refresh status (5s interval)", value=False)
192
+ auto_refresh_logs_cb = gr.Checkbox(label="Auto-refresh logs (10s interval)", value=False)
193
+
194
+ # Logs Section
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  with gr.Group(elem_classes=["enterprise-container"]):
196
  gr.HTML('<div class="container-header">📋 System Logs</div>')
197
  with gr.Group(elem_classes=["container-content"]):
198
  with gr.Row():
199
  fetch_logs_btn = gr.Button("Fetch Application Logs", elem_classes=["btn-secondary"])
200
  gr.HTML('<div style="flex-grow: 1;"></div>')
 
201
  gr.HTML('<div class="form-label mt-4">Runtime Logs</div>')
202
+ logs_display = gr.Textbox(lines=14, interactive=False, elem_classes=["terminal-logs"], placeholder="[SYSTEM] Logs will appear here...", show_label=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
+ # Event Handlers
205
+ connect_btn.click(fn=sandbox.connect, outputs=[connection_status, current_engine_display])
206
+ load_samples_btn.click(fn=load_sample_files, outputs=[main_py_editor, requirements_editor])
207
+ launch_btn.click(fn=sandbox.launch_sandbox, inputs=[main_py_editor, requirements_editor], outputs=[launch_output, status_display])
208
+ kill_btn.click(fn=sandbox.kill_sandbox, outputs=[launch_output, status_display])
209
+ fetch_logs_btn.click(fn=sandbox.fetch_logs, outputs=logs_display)
210
+ status_refresh_btn.click(fn=auto_refresh_status, outputs=status_display)
211
+
212
+ demo.launch()