Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,7 +45,7 @@ class SandboxManager:
|
|
| 45 |
requirements=requirements_txt,
|
| 46 |
api_name="/launch_sandbox"
|
| 47 |
)
|
| 48 |
-
return f"
|
| 49 |
except Exception as e:
|
| 50 |
return f"β Launch failed: {str(e)}", ""
|
| 51 |
|
|
@@ -56,9 +56,9 @@ class SandboxManager:
|
|
| 56 |
try:
|
| 57 |
result = self.client.predict(api_name="/fetch_logs")
|
| 58 |
timestamp = datetime.now().strftime("%H:%M:%S")
|
| 59 |
-
return f"
|
| 60 |
except Exception as e:
|
| 61 |
-
return f"
|
| 62 |
|
| 63 |
def kill_sandbox(self):
|
| 64 |
if not self.is_connected:
|
|
@@ -66,7 +66,7 @@ class SandboxManager:
|
|
| 66 |
|
| 67 |
try:
|
| 68 |
result = self.client.predict(api_name="/kill_sandbox")
|
| 69 |
-
return f"
|
| 70 |
except Exception as e:
|
| 71 |
return f"β Kill failed: {str(e)}", ""
|
| 72 |
|
|
@@ -87,186 +87,317 @@ sandbox = SandboxManager()
|
|
| 87 |
# Sample code templates
|
| 88 |
SAMPLE_MAIN_PY = """#!/usr/bin/env python3
|
| 89 |
\"\"\"
|
| 90 |
-
|
| 91 |
-
|
| 92 |
\"\"\"
|
| 93 |
|
| 94 |
import os
|
| 95 |
import sys
|
|
|
|
| 96 |
from datetime import datetime
|
| 97 |
|
| 98 |
def main():
|
| 99 |
-
print("
|
| 100 |
-
print(
|
| 101 |
-
print(f"
|
| 102 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
print(
|
| 106 |
|
| 107 |
-
# Example
|
| 108 |
-
numbers =
|
| 109 |
-
result = sum(numbers)
|
| 110 |
-
print(f"
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
main()
|
| 114 |
"""
|
| 115 |
|
| 116 |
-
SAMPLE_REQUIREMENTS_TXT = """# Python
|
| 117 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
#
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
# Web frameworks
|
| 124 |
-
# flask
|
| 125 |
-
# fastapi
|
|
|
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
#
|
| 129 |
-
#
|
| 130 |
|
| 131 |
-
#
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
-
#
|
|
|
|
|
|
|
| 136 |
"""
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
.gradio-container {
|
| 141 |
-
font-family: '
|
| 142 |
-
background:
|
|
|
|
| 143 |
min-height: 100vh;
|
|
|
|
|
|
|
| 144 |
}
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
padding:
|
| 151 |
-
margin:
|
| 152 |
-
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
-
.
|
| 156 |
-
background:
|
| 157 |
-
color:
|
| 158 |
-
padding:
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
font-weight: 600;
|
| 162 |
-
margin: 10px 0;
|
| 163 |
-
font-family: 'JetBrains Mono', monospace;
|
| 164 |
-
box-shadow: 0 8px 20px rgba(0, 114, 255, 0.3);
|
| 165 |
}
|
| 166 |
|
| 167 |
-
.
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
margin: 10px 0;
|
| 173 |
-
font-weight: 600;
|
| 174 |
-
text-align: center;
|
| 175 |
-
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
|
| 176 |
}
|
| 177 |
|
| 178 |
-
.
|
| 179 |
-
|
| 180 |
-
border:
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
| 184 |
}
|
| 185 |
|
| 186 |
-
.
|
| 187 |
-
|
| 188 |
-
border:
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
|
| 194 |
-
.
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
| 199 |
color: white !important;
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
font-size:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
}
|
| 205 |
|
| 206 |
-
.
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
}
|
| 210 |
|
| 211 |
-
.
|
| 212 |
-
background:
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
}
|
| 215 |
|
| 216 |
-
.
|
| 217 |
-
|
| 218 |
}
|
| 219 |
|
| 220 |
-
.
|
| 221 |
-
|
| 222 |
-
color: #
|
| 223 |
-
border
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
font-size: 13px !important;
|
| 226 |
-
line-height: 1.6 !important;
|
| 227 |
-
border: 1px solid #30363d !important;
|
| 228 |
-
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3) !important;
|
| 229 |
}
|
| 230 |
|
| 231 |
-
.
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
font-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
}
|
| 242 |
|
| 243 |
-
.
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
}
|
| 250 |
|
| 251 |
-
.
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
}
|
| 256 |
|
| 257 |
-
.
|
| 258 |
-
|
| 259 |
-
margin-right: 8px;
|
| 260 |
}
|
| 261 |
|
| 262 |
-
.
|
| 263 |
-
background:
|
| 264 |
-
|
| 265 |
-
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
font-size:
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
}
|
| 271 |
"""
|
| 272 |
|
|
@@ -280,116 +411,156 @@ def load_sample_files():
|
|
| 280 |
"""Load sample files into the editors"""
|
| 281 |
return SAMPLE_MAIN_PY, SAMPLE_REQUIREMENTS_TXT
|
| 282 |
|
| 283 |
-
# Build the
|
| 284 |
-
with gr.Blocks(css=
|
|
|
|
|
|
|
| 285 |
gr.HTML("""
|
| 286 |
-
<div class="header
|
| 287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
""")
|
| 289 |
|
|
|
|
|
|
|
|
|
|
| 290 |
with gr.Row():
|
|
|
|
| 291 |
with gr.Column(scale=3):
|
| 292 |
-
#
|
| 293 |
-
with gr.Group(elem_classes=["
|
| 294 |
-
gr.HTML('<div class="
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
|
| 314 |
-
#
|
| 315 |
-
with gr.Group(elem_classes=["
|
| 316 |
-
gr.HTML('<div class="
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
show_label=False
|
| 326 |
)
|
| 327 |
-
|
| 328 |
-
with gr.Tab("π¦ requirements.txt"):
|
| 329 |
-
requirements_editor = gr.Textbox(
|
| 330 |
-
value="# Add your Python package dependencies here\n# One package per line\n",
|
| 331 |
-
label="requirements.txt",
|
| 332 |
-
lines=20,
|
| 333 |
-
elem_classes=["requirements-editor"],
|
| 334 |
-
show_label=False,
|
| 335 |
-
max_lines=20
|
| 336 |
-
)
|
| 337 |
-
|
| 338 |
-
# Control Buttons
|
| 339 |
-
with gr.Row():
|
| 340 |
-
launch_btn = gr.Button("π Deploy & Run", variant="primary", elem_classes=["action-button"], size="lg")
|
| 341 |
-
kill_btn = gr.Button("π Stop Sandbox", elem_classes=["action-button", "stop-button"], size="lg")
|
| 342 |
-
|
| 343 |
-
# Launch Output
|
| 344 |
-
launch_output = gr.Textbox(
|
| 345 |
-
label="Deployment Output",
|
| 346 |
-
lines=6,
|
| 347 |
-
interactive=False,
|
| 348 |
-
placeholder="Deployment status will appear here...",
|
| 349 |
-
elem_classes=["logs-output"]
|
| 350 |
-
)
|
| 351 |
|
|
|
|
| 352 |
with gr.Column(scale=1):
|
| 353 |
-
# Status
|
| 354 |
-
with gr.Group(elem_classes=["
|
| 355 |
-
gr.HTML('<div class="
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
-
#
|
| 378 |
-
with gr.Group(elem_classes=["
|
| 379 |
-
gr.HTML('<div class="
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
|
| 394 |
# Event Handlers
|
| 395 |
connect_btn.click(
|
|
@@ -454,11 +625,9 @@ with gr.Blocks(css=custom_css, title="Sandbox Cloud IDE", theme=gr.themes.Soft()
|
|
| 454 |
|
| 455 |
# Footer
|
| 456 |
gr.HTML("""
|
| 457 |
-
<div style="text-align: center; margin-top:
|
| 458 |
-
<p
|
| 459 |
-
<p
|
| 460 |
-
Available Engines: SANDBOXBACKEND1, SANDBOXBACKEND2
|
| 461 |
-
</p>
|
| 462 |
</div>
|
| 463 |
""")
|
| 464 |
|
|
|
|
| 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 |
|
|
|
|
| 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:
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
| 565 |
# Event Handlers
|
| 566 |
connect_btn.click(
|
|
|
|
| 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 |
|