theguywhosucks commited on
Commit
12e19da
Β·
verified Β·
1 Parent(s): 0e92a82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +426 -331
app.py CHANGED
@@ -29,15 +29,15 @@ class SandboxManager:
29
  try:
30
  self.client = Client(engine)
31
  self.is_connected = True
32
- return f"βœ… Connected to: {engine}", engine
33
  except Exception as e:
34
  self.is_connected = False
35
  self.current_engine = None
36
- return f"❌ Connection failed to {engine}: {str(e)}", "Not connected"
37
 
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(
@@ -45,359 +45,458 @@ class SandboxManager:
45
  requirements=requirements_txt,
46
  api_name="/launch_sandbox"
47
  )
48
- return f"βœ… Sandbox launched successfully on {self.current_engine}!\n\nResponse: {result}", self.get_status()
49
  except Exception as e:
50
- return f"❌ Launch failed: {str(e)}", ""
51
 
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")
59
- return f"Logs fetched at {timestamp} from {self.current_engine}:\n\n{result}"
60
  except Exception as e:
61
- return f"Failed to fetch logs: {str(e)}"
62
 
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()
70
  except Exception as e:
71
- return f"❌ Kill failed: {str(e)}", ""
72
 
73
  def get_status(self):
74
  if not self.is_connected:
75
- return "πŸ”΄ Disconnected"
76
 
77
  try:
78
  result = self.client.predict(api_name="/status_sandbox")
79
- status_emoji = "🟒" if "running" in str(result).lower() else "🟑"
80
- return f"{status_emoji} Status: {result}"
 
 
81
  except Exception as e:
82
- return f"πŸ”΄ Status check failed: {str(e)}"
83
 
84
  # Initialize sandbox manager
85
  sandbox = SandboxManager()
86
 
87
- # Sample code templates
88
  SAMPLE_MAIN_PY = """#!/usr/bin/env python3
89
  \"\"\"
90
- AWS Sandbox Environment
91
- Python Application Template
92
  \"\"\"
93
 
94
  import os
95
  import sys
96
  import json
97
- from datetime import datetime
98
-
99
- def main():
100
- print("AWS Sandbox Environment - Python Runtime")
101
- print("=" * 50)
102
- print(f"Timestamp: {datetime.now().isoformat()}")
103
- print(f"Python Version: {sys.version}")
104
- print(f"Working Directory: {os.getcwd()}")
105
- print("=" * 50)
 
 
 
 
106
 
107
- # Application logic here
108
- data = {
109
- "service": "aws-sandbox",
110
- "status": "running",
111
- "timestamp": datetime.now().isoformat(),
112
- "environment": "production"
113
  }
114
 
115
- print("Application Output:")
116
- print(json.dumps(data, indent=2))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- # Example computation
119
- numbers = list(range(1, 11))
120
- result = sum(x**2 for x in numbers)
121
- print(f"\\nComputation Result: Sum of squares 1-10 = {result}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  if __name__ == "__main__":
124
  main()
125
  """
126
 
127
- SAMPLE_REQUIREMENTS_TXT = """# AWS Sandbox - Python Dependencies
128
- # Production-ready package versions
129
-
130
- # Core utilities
131
- requests==2.31.0
132
- python-dateutil==2.8.2
133
- pytz==2023.3
134
-
135
- # Data processing
136
- numpy==1.24.3
137
- pandas==2.0.3
138
-
139
- # AWS SDK (if needed)
140
- # boto3==1.28.25
141
- # botocore==1.31.25
142
-
143
- # Web frameworks
144
- # flask==2.3.2
145
- # fastapi==0.100.0
146
- # uvicorn==0.23.1
147
-
148
- # Database drivers
149
- # psycopg2-binary==2.9.7
150
- # pymongo==4.4.1
151
-
152
- # Scientific computing
153
- # scipy==1.11.1
154
- # scikit-learn==1.3.0
155
-
156
- # Development tools
157
- # pytest==7.4.0
158
- # black==23.7.0
 
 
 
 
 
 
 
 
159
  """
160
 
161
- # AWS-style CSS
162
- aws_css = """
163
- @import url('https://fonts.googleapis.com/css2?family=Amazon+Ember:wght@300;400;500;600;700&display=swap');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  .gradio-container {
166
- font-family: 'Amazon Ember', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
167
- background-color: #f2f3f3 !important;
168
- color: #232f3e !important;
169
  min-height: 100vh;
170
- margin: 0;
171
- padding: 0;
172
  }
173
 
174
- /* AWS Header */
175
- .aws-header {
176
- background-color: #232f3e !important;
177
  color: white !important;
178
- padding: 12px 20px !important;
179
- margin: 0 !important;
180
- border-bottom: 1px solid #3c4043 !important;
181
- font-size: 14px !important;
182
- font-weight: 500 !important;
183
  }
184
 
185
- .aws-nav {
186
- background-color: #37475a !important;
187
- color: #ffffff !important;
188
- padding: 8px 20px !important;
189
- font-size: 13px !important;
190
- border-bottom: 1px solid #485563 !important;
191
  }
192
 
193
- .aws-service-title {
194
- font-size: 20px !important;
195
- font-weight: 500 !important;
196
- color: #232f3e !important;
197
- margin: 20px 0 10px 0 !important;
198
  }
199
 
200
- .aws-container {
201
- background-color: white !important;
202
- border: 1px solid #d5dbdb !important;
203
- border-radius: 8px !important;
204
- margin: 16px !important;
205
- padding: 0 !important;
206
- box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
207
  }
208
 
209
- .aws-container-header {
210
- background-color: #fafbfc !important;
211
- border-bottom: 1px solid #d5dbdb !important;
212
- padding: 16px 20px !important;
213
- font-weight: 500 !important;
214
- color: #232f3e !important;
 
 
 
 
 
 
 
 
 
215
  font-size: 16px !important;
216
- border-radius: 8px 8px 0 0 !important;
 
 
 
217
  }
218
 
219
- .aws-container-content {
220
- padding: 20px !important;
221
  }
222
 
223
- .aws-button-primary {
224
- background-color: #ec7211 !important;
 
225
  color: white !important;
226
- border: 1px solid #ec7211 !important;
227
- border-radius: 4px !important;
228
- padding: 8px 16px !important;
229
  font-size: 14px !important;
230
  font-weight: 500 !important;
231
- cursor: pointer !important;
232
  transition: all 0.2s ease !important;
 
233
  }
234
 
235
- .aws-button-primary:hover {
236
- background-color: #d86613 !important;
237
- border-color: #d86613 !important;
238
  }
239
 
240
- .aws-button-secondary {
241
- background-color: white !important;
242
- color: #232f3e !important;
243
- border: 1px solid #d5dbdb !important;
244
- border-radius: 4px !important;
245
- padding: 8px 16px !important;
246
  font-size: 14px !important;
247
  font-weight: 500 !important;
248
- cursor: pointer !important;
249
  transition: all 0.2s ease !important;
250
  }
251
 
252
- .aws-button-secondary:hover {
253
- background-color: #f2f3f3 !important;
254
- border-color: #879596 !important;
255
  }
256
 
257
- .aws-button-danger {
258
- background-color: #d13212 !important;
259
  color: white !important;
260
- border: 1px solid #d13212 !important;
261
- border-radius: 4px !important;
262
- padding: 8px 16px !important;
263
  font-size: 14px !important;
264
  font-weight: 500 !important;
265
- cursor: pointer !important;
 
266
  }
267
 
268
- .aws-button-danger:hover {
269
- background-color: #b02e0c !important;
 
 
 
 
 
 
 
270
  }
271
 
272
- .aws-status-success {
273
- color: #1d8102 !important;
274
- background-color: #e6f3e6 !important;
275
- border: 1px solid #7aa116 !important;
276
- border-radius: 4px !important;
277
- padding: 12px 16px !important;
278
- font-size: 14px !important;
279
- font-weight: 500 !important;
280
  }
281
 
282
- .aws-status-error {
283
- color: #d13212 !important;
284
- background-color: #fdf2f2 !important;
285
- border: 1px solid #d13212 !important;
286
- border-radius: 4px !important;
287
- padding: 12px 16px !important;
288
- font-size: 14px !important;
289
- font-weight: 500 !important;
290
  }
291
 
292
- .aws-status-warning {
293
- color: #b7911a !important;
294
- background-color: #fffbf0 !important;
295
- border: 1px solid #b7911a !important;
296
- border-radius: 4px !important;
297
- padding: 12px 16px !important;
298
  font-size: 14px !important;
299
- font-weight: 500 !important;
 
300
  }
301
 
302
- .aws-code-editor {
303
- font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace !important;
304
- background-color: #1e1e1e !important;
305
- border: 1px solid #d5dbdb !important;
306
- border-radius: 4px !important;
307
  font-size: 13px !important;
308
- }
309
-
310
- .aws-logs {
311
- font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace !important;
312
- background-color: #232f3e !important;
313
- color: #ffffff !important;
314
- border: 1px solid #d5dbdb !important;
315
- border-radius: 4px !important;
316
- font-size: 12px !important;
317
  line-height: 1.4 !important;
318
  }
319
 
320
- .aws-form-group {
321
- margin-bottom: 16px !important;
322
- }
323
-
324
- .aws-form-label {
325
- font-size: 14px !important;
326
- font-weight: 500 !important;
327
- color: #232f3e !important;
328
- margin-bottom: 4px !important;
329
- display: block !important;
330
  }
331
 
332
- .aws-sidebar {
333
- background-color: white !important;
334
- border: 1px solid #d5dbdb !important;
335
- border-radius: 8px !important;
336
- padding: 0 !important;
 
 
337
  height: fit-content !important;
338
  }
339
 
340
- .aws-sidebar-header {
341
- background-color: #fafbfc !important;
342
- border-bottom: 1px solid #d5dbdb !important;
343
  padding: 12px 16px !important;
344
- font-weight: 500 !important;
345
- color: #232f3e !important;
346
  font-size: 14px !important;
347
- border-radius: 8px 8px 0 0 !important;
 
348
  }
349
 
350
- .aws-sidebar-content {
351
  padding: 16px !important;
352
  }
353
 
354
- .aws-info-box {
355
- background-color: #f0f8ff !important;
356
- border: 1px solid #4a90e2 !important;
357
- border-radius: 4px !important;
358
- padding: 12px !important;
359
- margin: 8px 0 !important;
360
- font-size: 13px !important;
361
- color: #232f3e !important;
362
- }
363
-
364
- .aws-breadcrumb {
365
- font-size: 12px !important;
366
- color: #687078 !important;
367
- margin: 8px 20px !important;
368
  }
369
 
370
- .aws-tabs {
371
- border: 1px solid #d5dbdb !important;
372
- border-radius: 8px !important;
373
- background-color: white !important;
374
- overflow: hidden !important;
 
375
  }
376
 
377
- .aws-tab-content {
378
- padding: 16px !important;
 
 
 
 
 
 
379
  }
380
 
381
- .aws-metric {
 
382
  text-align: center !important;
383
- padding: 12px !important;
384
- border-right: 1px solid #d5dbdb !important;
385
  }
386
 
387
- .aws-metric:last-child {
388
  border-right: none !important;
389
  }
390
 
391
- .aws-metric-value {
392
- font-size: 24px !important;
393
- font-weight: 600 !important;
394
- color: #232f3e !important;
 
395
  }
396
 
397
- .aws-metric-label {
398
  font-size: 12px !important;
399
- color: #687078 !important;
400
  margin-top: 4px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  }
402
  """
403
 
@@ -408,157 +507,151 @@ def auto_refresh_logs():
408
  return sandbox.fetch_logs()
409
 
410
  def load_sample_files():
411
- """Load sample files into the editors"""
412
  return SAMPLE_MAIN_PY, SAMPLE_REQUIREMENTS_TXT
413
 
414
- # Build the AWS-style interface
415
- with gr.Blocks(css=aws_css, title="AWS Sandbox Service", theme=gr.themes.Default()) as demo:
416
 
417
- # AWS Header
418
  gr.HTML("""
419
- <div class="aws-header">
420
- <span>πŸ”Ά Amazon Web Services</span>
421
- <span style="float: right;">Sandbox Compute Service</span>
422
- </div>
423
- <div class="aws-nav">
424
- Services > Compute > Sandbox > Management Console
425
  </div>
426
- <div class="aws-breadcrumb">
427
- Home > Sandbox Service > Console
428
  </div>
429
  """)
430
 
431
- # Service Title
432
- gr.HTML('<div class="aws-service-title">Sandbox Compute Service</div>')
433
-
434
  with gr.Row():
435
  # Main Content Area
436
  with gr.Column(scale=3):
437
- # Connection Management
438
- with gr.Group(elem_classes=["aws-container"]):
439
- gr.HTML('<div class="aws-container-header">πŸ”— Engine Connection</div>')
440
- with gr.Group(elem_classes=["aws-container-content"]):
441
  with gr.Row():
442
- connect_btn = gr.Button("Connect to Engine", elem_classes=["aws-button-primary"])
443
- load_samples_btn = gr.Button("Load Sample Code", elem_classes=["aws-button-secondary"])
444
 
 
445
  current_engine_display = gr.Textbox(
446
  value="No engine selected",
447
- label="Active Compute Engine",
448
  interactive=False,
449
- elem_classes=["aws-info-box"]
 
450
  )
451
 
 
452
  connection_status = gr.Textbox(
453
- value="Disconnected",
454
- label="Connection Status",
455
  interactive=False,
456
- elem_classes=["aws-status-error"]
 
457
  )
458
 
459
- # Code Development Environment
460
- with gr.Group(elem_classes=["aws-container"]):
461
- gr.HTML('<div class="aws-container-header">πŸ’» Development Environment</div>')
462
- with gr.Group(elem_classes=["aws-container-content"]):
463
- with gr.Tab("main.py", elem_classes=["aws-tabs"]):
464
- with gr.Group(elem_classes=["aws-tab-content"]):
465
- gr.HTML('<div class="aws-form-label">πŸ“„ Application Code (main.py)</div>')
466
- main_py_editor = gr.Code(
467
- value="# AWS Sandbox Python Application\nprint('Hello from AWS Sandbox!')",
468
- language="python",
469
- lines=18,
470
- elem_classes=["aws-code-editor"],
471
- show_label=False
472
- )
473
 
474
- with gr.Tab("requirements.txt", elem_classes=["aws-tabs"]):
475
- with gr.Group(elem_classes=["aws-tab-content"]):
476
- gr.HTML('<div class="aws-form-label">πŸ“¦ Dependencies (requirements.txt)</div>')
477
- requirements_editor = gr.Textbox(
478
- value="# Add Python package dependencies\n# Example: requests>=2.25.0",
479
- lines=18,
480
- elem_classes=["aws-code-editor"],
481
- show_label=False,
482
- max_lines=25
483
- )
484
 
485
- # Deployment Actions
486
- gr.HTML('<div style="margin-top: 16px;"></div>')
487
  with gr.Row():
488
- launch_btn = gr.Button("Deploy Application", elem_classes=["aws-button-primary"], size="lg")
489
- kill_btn = gr.Button("Terminate Instance", elem_classes=["aws-button-danger"], size="lg")
490
 
491
- # Deployment Output
492
- gr.HTML('<div class="aws-form-label" style="margin-top: 16px;">Deployment Status</div>')
493
  launch_output = gr.Textbox(
494
  lines=6,
495
  interactive=False,
496
- placeholder="Deployment status and output will appear here...",
497
- elem_classes=["aws-logs"],
498
  show_label=False
499
  )
500
 
501
- # Sidebar
502
  with gr.Column(scale=1):
503
- # Instance Status
504
- with gr.Group(elem_classes=["aws-sidebar"]):
505
- gr.HTML('<div class="aws-sidebar-header">πŸ“Š Instance Status</div>')
506
- with gr.Group(elem_classes=["aws-sidebar-content"]):
 
507
  status_display = gr.Textbox(
508
- value="Stopped",
509
- label="Current Status",
510
  interactive=False,
511
- elem_classes=["aws-status-warning"]
 
512
  )
513
 
514
- status_refresh_btn = gr.Button("Refresh Status", elem_classes=["aws-button-secondary"], size="sm")
515
 
516
- gr.HTML('<div style="margin: 16px 0; border-bottom: 1px solid #d5dbdb;"></div>')
517
 
518
- # Auto-refresh controls
519
- gr.HTML('<div class="aws-form-label">Auto-Refresh Settings</div>')
520
  auto_refresh_status_cb = gr.Checkbox(
521
- label="Status monitoring (5s)",
522
  value=False
523
  )
524
  auto_refresh_logs_cb = gr.Checkbox(
525
- label="Log streaming (10s)",
526
  value=False
527
  )
528
 
529
- # Instance Metrics (placeholder)
530
- with gr.Group(elem_classes=["aws-sidebar"]):
531
- gr.HTML('<div class="aws-sidebar-header">πŸ“ˆ Metrics</div>')
532
- with gr.Group(elem_classes=["aws-sidebar-content"]):
533
- gr.HTML('''
534
- <div class="aws-metric">
535
- <div class="aws-metric-value">0</div>
536
- <div class="aws-metric-label">CPU Usage (%)</div>
537
  </div>
538
- <div class="aws-metric">
539
- <div class="aws-metric-value">0</div>
540
- <div class="aws-metric-label">Memory (MB)</div>
541
  </div>
542
- <div class="aws-metric">
543
- <div class="aws-metric-value">0</div>
544
- <div class="aws-metric-label">Uptime (min)</div>
545
  </div>
546
- ''')
 
547
 
548
- # Logs Section
549
- with gr.Group(elem_classes=["aws-container"]):
550
- gr.HTML('<div class="aws-container-header">πŸ“‹ Application Logs</div>')
551
- with gr.Group(elem_classes=["aws-container-content"]):
552
  with gr.Row():
553
- fetch_logs_btn = gr.Button("Fetch Logs", elem_classes=["aws-button-secondary"])
554
  gr.HTML('<div style="flex-grow: 1;"></div>')
555
 
556
- gr.HTML('<div class="aws-form-label" style="margin-top: 12px;">CloudWatch Logs</div>')
557
  logs_display = gr.Textbox(
558
- lines=12,
559
  interactive=False,
560
- elem_classes=["aws-logs"],
561
- placeholder="Application logs will appear here...\n\nLogs are automatically captured from your running application.",
562
  show_label=False
563
  )
564
 
@@ -623,11 +716,13 @@ with gr.Blocks(css=aws_css, title="AWS Sandbox Service", theme=gr.themes.Default
623
  outputs=[logs_timer]
624
  )
625
 
626
- # Footer
627
  gr.HTML("""
628
- <div style="text-align: center; margin-top: 40px; padding: 20px; background-color: #fafbfc; border-top: 1px solid #d5dbdb; color: #687078; font-size: 12px;">
629
- <p>Β© 2025, Choco Labs, Inc. All rights reserved.</p>
630
- <p>Sandbox Compute Service β€’ Dual-Engine Architecture </p>
 
 
631
  </div>
632
  """)
633
 
 
29
  try:
30
  self.client = Client(engine)
31
  self.is_connected = True
32
+ return f"βœ“ Connected to: {engine}", engine
33
  except Exception as e:
34
  self.is_connected = False
35
  self.current_engine = None
36
+ return f"βœ— Connection failed to {engine}: {str(e)}", "Not connected"
37
 
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(
 
45
  requirements=requirements_txt,
46
  api_name="/launch_sandbox"
47
  )
48
+ return f"βœ“ Sandbox deployed successfully on {self.current_engine}\n\nResponse: {result}", self.get_status()
49
  except Exception as e:
50
+ return f"βœ— Deployment failed: {str(e)}", ""
51
 
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")
59
+ return f"[{timestamp}] Logs from {self.current_engine}:\n\n{result}"
60
  except Exception as e:
61
+ return f"[ERROR] Failed to fetch logs: {str(e)}"
62
 
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()
70
  except Exception as e:
71
+ return f"βœ— Termination failed: {str(e)}", ""
72
 
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():
80
+ return f"RUNNING - {result}"
81
+ else:
82
+ return f"IDLE - {result}"
83
  except Exception as e:
84
+ return f"ERROR - {str(e)}"
85
 
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
 
 
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
 
 
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