Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +240 -560
index.html
CHANGED
|
@@ -1,572 +1,252 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
.header {
|
| 28 |
-
text-align: center;
|
| 29 |
-
margin-bottom: 2rem;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
.header h1 {
|
| 33 |
-
font-size: 2.5rem;
|
| 34 |
-
font-weight: bold;
|
| 35 |
-
color: #1f2937;
|
| 36 |
-
margin-bottom: 0.5rem;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
.header p {
|
| 40 |
-
color: #6b7280;
|
| 41 |
-
font-size: 1.1rem;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
.card {
|
| 45 |
-
background: white;
|
| 46 |
-
border-radius: 0.5rem;
|
| 47 |
-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
| 48 |
-
padding: 1.5rem;
|
| 49 |
-
margin-bottom: 1.5rem;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
.form-group {
|
| 53 |
-
margin-bottom: 1rem;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
.form-label {
|
| 57 |
-
display: block;
|
| 58 |
-
font-size: 0.875rem;
|
| 59 |
-
font-weight: 500;
|
| 60 |
-
color: #374151;
|
| 61 |
-
margin-bottom: 0.5rem;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
.textarea {
|
| 65 |
-
width: 100%;
|
| 66 |
-
padding: 0.75rem;
|
| 67 |
-
border: 1px solid #d1d5db;
|
| 68 |
-
border-radius: 0.375rem;
|
| 69 |
-
font-size: 1rem;
|
| 70 |
-
resize: vertical;
|
| 71 |
-
min-height: 100px;
|
| 72 |
-
font-family: inherit;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
.textarea:focus {
|
| 76 |
-
outline: none;
|
| 77 |
-
border-color: #3b82f6;
|
| 78 |
-
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
.button-group {
|
| 82 |
-
display: flex;
|
| 83 |
-
flex-wrap: wrap;
|
| 84 |
-
gap: 0.75rem;
|
| 85 |
-
margin-top: 1rem;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
.btn {
|
| 89 |
-
padding: 0.75rem 1rem;
|
| 90 |
-
border: none;
|
| 91 |
-
border-radius: 0.375rem;
|
| 92 |
-
font-weight: 500;
|
| 93 |
-
cursor: pointer;
|
| 94 |
-
transition: all 0.2s ease;
|
| 95 |
-
display: flex;
|
| 96 |
-
align-items: center;
|
| 97 |
-
justify-content: center;
|
| 98 |
-
gap: 0.5rem;
|
| 99 |
-
font-size: 0.875rem;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
.btn:hover {
|
| 103 |
-
transform: translateY(-1px);
|
| 104 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
.btn:disabled {
|
| 108 |
-
opacity: 0.6;
|
| 109 |
-
cursor: not-allowed;
|
| 110 |
-
transform: none;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
.btn-primary {
|
| 114 |
-
background-color: #3b82f6;
|
| 115 |
-
color: white;
|
| 116 |
-
flex: 1;
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
.btn-primary:hover:not(:disabled) {
|
| 120 |
-
background-color: #2563eb;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
.btn-secondary {
|
| 124 |
-
background-color: #f97316;
|
| 125 |
-
color: white;
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
.btn-secondary:hover:not(:disabled) {
|
| 129 |
-
background-color: #ea580c;
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
.btn-gray {
|
| 133 |
-
background-color: #6b7280;
|
| 134 |
-
color: white;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
.btn-gray:hover:not(:disabled) {
|
| 138 |
-
background-color: #4b5563;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
.btn-light {
|
| 142 |
-
background-color: #f3f4f6;
|
| 143 |
-
color: #374151;
|
| 144 |
-
padding: 0.5rem 0.75rem;
|
| 145 |
-
font-size: 0.8rem;
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
.btn-light:hover:not(:disabled) {
|
| 149 |
-
background-color: #e5e7eb;
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
.output-header {
|
| 153 |
-
display: flex;
|
| 154 |
-
justify-content: space-between;
|
| 155 |
-
align-items: center;
|
| 156 |
-
margin-bottom: 1rem;
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
.output-title {
|
| 160 |
-
font-size: 1.125rem;
|
| 161 |
-
font-weight: 600;
|
| 162 |
-
color: #1f2937;
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
.button-controls {
|
| 166 |
-
display: flex;
|
| 167 |
-
gap: 0.5rem;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
.code-container {
|
| 171 |
-
background-color: #1f2937;
|
| 172 |
-
border-radius: 0.5rem;
|
| 173 |
-
padding: 1rem;
|
| 174 |
-
overflow-x: auto;
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
.code-output {
|
| 178 |
-
color: #e5e7eb;
|
| 179 |
-
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
| 180 |
-
font-size: 0.875rem;
|
| 181 |
-
line-height: 1.5;
|
| 182 |
-
white-space: pre-wrap;
|
| 183 |
-
word-wrap: break-word;
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
.modal {
|
| 187 |
-
position: fixed;
|
| 188 |
-
top: 0;
|
| 189 |
-
left: 0;
|
| 190 |
-
right: 0;
|
| 191 |
-
bottom: 0;
|
| 192 |
-
background-color: rgba(0, 0, 0, 0.5);
|
| 193 |
-
display: none;
|
| 194 |
-
align-items: center;
|
| 195 |
-
justify-content: center;
|
| 196 |
-
padding: 1rem;
|
| 197 |
-
z-index: 1000;
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
.modal.show {
|
| 201 |
-
display: flex;
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
.modal-content {
|
| 205 |
-
background: white;
|
| 206 |
-
border-radius: 0.5rem;
|
| 207 |
-
box-shadow: 0 20px 25px rgba(0, 0, 0, 0.1);
|
| 208 |
-
max-width: 32rem;
|
| 209 |
-
width: 100%;
|
| 210 |
-
max-height: 24rem;
|
| 211 |
-
overflow: hidden;
|
| 212 |
-
animation: modalSlideIn 0.3s ease-out;
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
@keyframes modalSlideIn {
|
| 216 |
-
from {
|
| 217 |
-
opacity: 0;
|
| 218 |
-
transform: translateY(-20px);
|
| 219 |
-
}
|
| 220 |
-
to {
|
| 221 |
-
opacity: 1;
|
| 222 |
-
transform: translateY(0);
|
| 223 |
-
}
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
.modal-header {
|
| 227 |
-
display: flex;
|
| 228 |
-
justify-content: space-between;
|
| 229 |
-
align-items: center;
|
| 230 |
-
padding: 1rem;
|
| 231 |
-
border-bottom: 1px solid #e5e7eb;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
.modal-title {
|
| 235 |
-
font-size: 1.125rem;
|
| 236 |
-
font-weight: 600;
|
| 237 |
-
color: #1f2937;
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
.modal-close {
|
| 241 |
-
background: none;
|
| 242 |
-
border: none;
|
| 243 |
-
color: #9ca3af;
|
| 244 |
-
cursor: pointer;
|
| 245 |
-
padding: 0.25rem;
|
| 246 |
-
border-radius: 0.25rem;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
.modal-close:hover {
|
| 250 |
-
color: #6b7280;
|
| 251 |
-
background-color: #f3f4f6;
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
.modal-body {
|
| 255 |
-
padding: 1rem;
|
| 256 |
-
overflow-y: auto;
|
| 257 |
-
max-height: 20rem;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
.toast {
|
| 261 |
-
position: fixed;
|
| 262 |
-
top: 1rem;
|
| 263 |
-
right: 1rem;
|
| 264 |
-
padding: 0.75rem 1rem;
|
| 265 |
-
border-radius: 0.375rem;
|
| 266 |
-
color: white;
|
| 267 |
-
font-weight: 500;
|
| 268 |
-
transform: translateX(100%);
|
| 269 |
-
transition: transform 0.3s ease;
|
| 270 |
-
z-index: 1100;
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
.toast.show {
|
| 274 |
-
transform: translateX(0);
|
| 275 |
-
}
|
| 276 |
-
|
| 277 |
-
.toast.success {
|
| 278 |
-
background-color: #10b981;
|
| 279 |
-
}
|
| 280 |
-
|
| 281 |
-
.toast.error {
|
| 282 |
-
background-color: #ef4444;
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
.toast.warning {
|
| 286 |
-
background-color: #f59e0b;
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
.loading {
|
| 290 |
-
animation: pulse 2s infinite;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
@keyframes pulse {
|
| 294 |
-
0%, 100% { opacity: 1; }
|
| 295 |
-
50% { opacity: 0.5; }
|
| 296 |
-
}
|
| 297 |
-
|
| 298 |
-
.spinner {
|
| 299 |
-
width: 1rem;
|
| 300 |
-
height: 1rem;
|
| 301 |
-
border: 2px solid transparent;
|
| 302 |
-
border-top: 2px solid currentColor;
|
| 303 |
-
border-radius: 50%;
|
| 304 |
-
animation: spin 1s linear infinite;
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
@keyframes spin {
|
| 308 |
-
to { transform: rotate(360deg); }
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
@media (max-width: 640px) {
|
| 312 |
-
.button-group {
|
| 313 |
-
flex-direction: column;
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
.btn-primary {
|
| 317 |
-
flex: none;
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
.output-header {
|
| 321 |
-
flex-direction: column;
|
| 322 |
-
gap: 1rem;
|
| 323 |
-
align-items: flex-start;
|
| 324 |
-
}
|
| 325 |
-
|
| 326 |
-
.button-controls {
|
| 327 |
-
align-self: stretch;
|
| 328 |
-
justify-content: space-between;
|
| 329 |
-
}
|
| 330 |
-
}
|
| 331 |
-
</style>
|
| 332 |
</head>
|
| 333 |
<body>
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
placeholder="e.g., Create a Python function to calculate fibonacci numbers..."
|
| 351 |
-
></textarea>
|
| 352 |
-
</div>
|
| 353 |
-
|
| 354 |
-
<!-- Action Buttons -->
|
| 355 |
-
<div class="button-group">
|
| 356 |
-
<button id="generateBtn" class="btn btn-primary">
|
| 357 |
-
<span>⚡</span>
|
| 358 |
-
Generate Code
|
| 359 |
-
</button>
|
| 360 |
-
|
| 361 |
-
<button id="explainBtn" class="btn btn-secondary">
|
| 362 |
-
<span>❓</span>
|
| 363 |
-
Explain Code
|
| 364 |
-
</button>
|
| 365 |
-
|
| 366 |
-
<button id="clearBtn" class="btn btn-gray">
|
| 367 |
-
<span>🗑️</span>
|
| 368 |
-
Clear
|
| 369 |
-
</button>
|
| 370 |
-
</div>
|
| 371 |
-
</div>
|
| 372 |
-
|
| 373 |
-
<!-- Output Section -->
|
| 374 |
-
<div class="card">
|
| 375 |
-
<div class="output-header">
|
| 376 |
-
<h2 class="output-title">Generated Code</h2>
|
| 377 |
-
<div class="button-controls">
|
| 378 |
-
<button id="copyBtn" class="btn btn-light">
|
| 379 |
-
<span>📋</span>
|
| 380 |
-
Copy Code
|
| 381 |
-
</button>
|
| 382 |
-
|
| 383 |
-
<button id="downloadBtn" class="btn btn-light">
|
| 384 |
-
<span>💾</span>
|
| 385 |
-
Download
|
| 386 |
-
</button>
|
| 387 |
-
</div>
|
| 388 |
-
</div>
|
| 389 |
-
|
| 390 |
-
<div class="code-container">
|
| 391 |
-
<pre id="codeOutput" class="code-output">// Your generated code will appear here...</pre>
|
| 392 |
-
</div>
|
| 393 |
-
</div>
|
| 394 |
</div>
|
| 395 |
|
| 396 |
-
|
| 397 |
-
<
|
| 398 |
-
<div class="modal-content">
|
| 399 |
-
<div class="modal-header">
|
| 400 |
-
<h3 class="modal-title">Code Explanation</h3>
|
| 401 |
-
<button id="closeModal" class="modal-close">
|
| 402 |
-
<span>✕</span>
|
| 403 |
-
</button>
|
| 404 |
-
</div>
|
| 405 |
-
<div class="modal-body">
|
| 406 |
-
<div id="explanationContent">
|
| 407 |
-
<!-- Explanation content will be inserted here -->
|
| 408 |
-
</div>
|
| 409 |
-
</div>
|
| 410 |
-
</div>
|
| 411 |
-
</div>
|
| 412 |
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
</div>
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
});
|
| 485 |
-
setLoading(explainBtn, true);
|
| 486 |
-
explanationContent.textContent = "⏳ Explaining code...";
|
| 487 |
-
|
| 488 |
-
try {
|
| 489 |
-
const res = await fetch(API_URL, {
|
| 490 |
-
method: "POST",
|
| 491 |
-
headers: { "Content-Type": "application/json" },
|
| 492 |
-
body: JSON.stringify({ data: [`Explain this code:\n\n${currentCode}`] })
|
| 493 |
-
});
|
| 494 |
-
|
| 495 |
-
const result = await res.json();
|
| 496 |
-
explanationContent.textContent = result?.data?.[0] || "⚠️ No explanation returned.";
|
| 497 |
-
explanationModal.classList.add('show');
|
| 498 |
-
} catch (err) {
|
| 499 |
-
console.error(err);
|
| 500 |
-
explanationContent.textContent = "❌ Error explaining code.";
|
| 501 |
-
} finally {
|
| 502 |
-
setLoading(explainBtn, false);
|
| 503 |
-
}
|
| 504 |
-
});
|
| 505 |
-
|
| 506 |
-
// Clear
|
| 507 |
-
clearBtn.addEventListener('click', () => {
|
| 508 |
-
promptTextarea.value = '';
|
| 509 |
-
currentCode = '';
|
| 510 |
-
codeOutput.textContent = '// Your generated code will appear here...';
|
| 511 |
-
showToast('Cleared successfully!', 'success');
|
| 512 |
-
});
|
| 513 |
-
|
| 514 |
-
// Copy Code
|
| 515 |
-
copyBtn.addEventListener('click', async () => {
|
| 516 |
-
if (!currentCode) {
|
| 517 |
-
showToast('No code to copy!', 'error');
|
| 518 |
-
return;
|
| 519 |
-
}
|
| 520 |
-
await navigator.clipboard.writeText(currentCode);
|
| 521 |
-
showToast('Code copied to clipboard!', 'success');
|
| 522 |
-
});
|
| 523 |
-
|
| 524 |
-
// Download Code
|
| 525 |
-
downloadBtn.addEventListener('click', () => {
|
| 526 |
-
if (!currentCode) {
|
| 527 |
-
showToast('No code to download!', 'error');
|
| 528 |
-
return;
|
| 529 |
-
}
|
| 530 |
-
const blob = new Blob([currentCode], { type: 'text/plain' });
|
| 531 |
-
const url = URL.createObjectURL(blob);
|
| 532 |
-
const a = document.createElement('a');
|
| 533 |
-
a.href = url;
|
| 534 |
-
a.download = 'generated_code.py';
|
| 535 |
-
document.body.appendChild(a);
|
| 536 |
-
a.click();
|
| 537 |
-
document.body.removeChild(a);
|
| 538 |
-
URL.revokeObjectURL(url);
|
| 539 |
-
});
|
| 540 |
-
|
| 541 |
-
// Modal
|
| 542 |
-
closeModal.addEventListener('click', () => {
|
| 543 |
-
explanationModal.classList.remove('show');
|
| 544 |
-
});
|
| 545 |
-
explanationModal.addEventListener('click', (e) => {
|
| 546 |
-
if (e.target === explanationModal) {
|
| 547 |
-
explanationModal.classList.remove('show');
|
| 548 |
-
}
|
| 549 |
-
});
|
| 550 |
-
|
| 551 |
-
// Utils
|
| 552 |
-
function setLoading(button, isLoading) {
|
| 553 |
-
if (isLoading) {
|
| 554 |
-
button.disabled = true;
|
| 555 |
-
button.setAttribute('data-original', button.innerHTML);
|
| 556 |
-
button.innerHTML = `<div class="spinner"></div> Loading...`;
|
| 557 |
-
} else {
|
| 558 |
-
button.disabled = false;
|
| 559 |
-
button.innerHTML = button.getAttribute('data-original');
|
| 560 |
-
}
|
| 561 |
}
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
}
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
</body>
|
| 572 |
-
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
| 6 |
+
<title>ColabMind Coder — ML & Python Code Generator</title>
|
| 7 |
+
<link rel="stylesheet" href="/static/style.css" />
|
| 8 |
+
<style>
|
| 9 |
+
/* Minimal inline CSS to ensure the page looks fine if /static/style.css missing */
|
| 10 |
+
body { font-family: Inter, system-ui, Arial; background:#f7fafc; color:#0f172a; margin:0; }
|
| 11 |
+
.container { max-width:1000px; margin:32px auto; padding:20px; background:white; box-shadow:0 6px 20px rgba(2,6,23,0.08); border-radius:12px; }
|
| 12 |
+
h1{margin:0 0 12px 0;font-size:1.6rem}
|
| 13 |
+
textarea#prompt{width:100%;min-height:120px;padding:12px;border-radius:8px;border:1px solid #e6edf3;resize:vertical;font-family:monospace}
|
| 14 |
+
.btn-row{display:flex;gap:8px;margin:12px 0}
|
| 15 |
+
button{padding:10px 14px;border-radius:8px;border:0;background:#2563eb;color:white;cursor:pointer}
|
| 16 |
+
button.secondary{background:#ff8a00}
|
| 17 |
+
button.ghost{background:#e6edf3;color:#0f172a}
|
| 18 |
+
pre#codeOutput{background:#0b1220;color:#dbeafe;padding:12px;border-radius:8px;overflow:auto;min-height:220px}
|
| 19 |
+
.small{font-size:0.9rem;color:#475569}
|
| 20 |
+
.toast{position:fixed;right:18px;bottom:18px;padding:10px 14px;border-radius:8px;background:#111827;color:white;opacity:0;transition:opacity .25s}
|
| 21 |
+
.toast.show{opacity:0.95}
|
| 22 |
+
/* modal */
|
| 23 |
+
.modal{position:fixed;left:0;top:0;width:100%;height:100%;display:none;align-items:center;justify-content:center;background:rgba(2,6,23,0.6)}
|
| 24 |
+
.modal.show{display:flex}
|
| 25 |
+
.modal-card{background:white;padding:16px;border-radius:8px;max-width:900px;width:95%;max-height:80vh;overflow:auto}
|
| 26 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
</head>
|
| 28 |
<body>
|
| 29 |
+
<div class="container">
|
| 30 |
+
<h1>ColabMind Coder — ML & Python Code Generator</h1>
|
| 31 |
+
<p class="small">Type a prompt (task or question) and press Generate. Use Explain to get inline explanations.</p>
|
| 32 |
+
|
| 33 |
+
<label for="prompt">Prompt</label>
|
| 34 |
+
<textarea id="prompt" placeholder="e.g., Write a PyTorch training loop for binary classification on tabular data with DataLoader and evaluation."></textarea>
|
| 35 |
+
|
| 36 |
+
<div class="btn-row">
|
| 37 |
+
<button id="generateBtn" data-original="Generate Code">Generate Code</button>
|
| 38 |
+
<button id="explainBtn" class="secondary" data-original="Explain Code">Explain Code</button>
|
| 39 |
+
<button id="clearBtn" class="ghost" data-original="Clear">Clear</button>
|
| 40 |
+
<div style="flex:1"></div>
|
| 41 |
+
<div style="display:flex;gap:8px">
|
| 42 |
+
<button id="copyBtn" class="ghost" data-original="Copy">Copy</button>
|
| 43 |
+
<button id="downloadBtn" class="ghost" data-original="Download">Download</button>
|
| 44 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
</div>
|
| 46 |
|
| 47 |
+
<label for="codeOutput">Generated Code</label>
|
| 48 |
+
<pre id="codeOutput" aria-label="Generated Code">// Generated code appears here</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
<div style="margin-top:12px; display:flex; gap:12px; align-items:center;">
|
| 51 |
+
<div class="small">History:</div>
|
| 52 |
+
<select id="historySelect"></select>
|
| 53 |
+
<button id="loadHistory" class="ghost">Load</button>
|
| 54 |
+
<button id="clearHistory" class="ghost">Clear History</button>
|
| 55 |
+
<div style="flex:1"></div>
|
| 56 |
+
<div class="small" id="statusText"></div>
|
| 57 |
</div>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<!-- explanation modal -->
|
| 61 |
+
<div id="explanationModal" class="modal" role="dialog" aria-modal="true">
|
| 62 |
+
<div class="modal-card">
|
| 63 |
+
<div style="display:flex;justify-content:space-between;align-items:center">
|
| 64 |
+
<h3>Explanation</h3>
|
| 65 |
+
<button id="closeModal" class="ghost">Close</button>
|
| 66 |
+
</div>
|
| 67 |
+
<pre id="explanationContent" style="white-space:pre-wrap;background:#f8fafc;padding:12px;border-radius:6px"></pre>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<div id="toast" class="toast"><span id="toastMessage"></span></div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
// ============ Config ============
|
| 75 |
+
// Relative endpoints work when frontend and backend are in same Space repo.
|
| 76 |
+
const PREDICT_URL = "/run/predict";
|
| 77 |
+
const EXPLAIN_URL = "/run/explain";
|
| 78 |
+
|
| 79 |
+
// History stored in sessionStorage (client-side) + server-side persistence handled by backend.
|
| 80 |
+
function loadLocalHistory(){
|
| 81 |
+
try{
|
| 82 |
+
const raw = sessionStorage.getItem('colabmind_history');
|
| 83 |
+
return raw ? JSON.parse(raw) : [];
|
| 84 |
+
}catch(e){ return []; }
|
| 85 |
+
}
|
| 86 |
+
function saveLocalHistory(hist){
|
| 87 |
+
try{ sessionStorage.setItem('colabmind_history', JSON.stringify(hist)); }catch(e){}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// DOM
|
| 91 |
+
const promptEl = document.getElementById('prompt');
|
| 92 |
+
const generateBtn = document.getElementById('generateBtn');
|
| 93 |
+
const explainBtn = document.getElementById('explainBtn');
|
| 94 |
+
const clearBtn = document.getElementById('clearBtn');
|
| 95 |
+
const copyBtn = document.getElementById('copyBtn');
|
| 96 |
+
const downloadBtn = document.getElementById('downloadBtn');
|
| 97 |
+
const codeOutput = document.getElementById('codeOutput');
|
| 98 |
+
const toast = document.getElementById('toast');
|
| 99 |
+
const toastMessage = document.getElementById('toastMessage');
|
| 100 |
+
const explanationModal = document.getElementById('explanationModal');
|
| 101 |
+
const explanationContent = document.getElementById('explanationContent');
|
| 102 |
+
const closeModal = document.getElementById('closeModal');
|
| 103 |
+
const historySelect = document.getElementById('historySelect');
|
| 104 |
+
const loadHistoryBtn = document.getElementById('loadHistory');
|
| 105 |
+
const clearHistoryBtn = document.getElementById('clearHistory');
|
| 106 |
+
const statusText = document.getElementById('statusText');
|
| 107 |
+
|
| 108 |
+
let history = loadLocalHistory();
|
| 109 |
+
refreshHistoryUI();
|
| 110 |
+
|
| 111 |
+
// ============ helpers ============
|
| 112 |
+
function showToast(msg, kind='info'){
|
| 113 |
+
toastMessage.textContent = msg;
|
| 114 |
+
toast.className = 'toast show';
|
| 115 |
+
setTimeout(()=> toast.classList.remove('show'), 3000);
|
| 116 |
+
}
|
| 117 |
+
function setLoading(btn, on=true){
|
| 118 |
+
if(on){
|
| 119 |
+
btn.disabled = true;
|
| 120 |
+
btn.dataset.orig = btn.innerHTML;
|
| 121 |
+
btn.innerHTML = '⏳ Loading...';
|
| 122 |
+
} else {
|
| 123 |
+
btn.disabled = false;
|
| 124 |
+
if(btn.dataset.orig) btn.innerHTML = btn.dataset.orig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// update history dropdown UI
|
| 129 |
+
function refreshHistoryUI(){
|
| 130 |
+
historySelect.innerHTML = '';
|
| 131 |
+
for(let i=0;i<history.length;i++){
|
| 132 |
+
const opt = document.createElement('option');
|
| 133 |
+
opt.value = i;
|
| 134 |
+
const p = history[i].prompt.replace(/\n/g,' ').slice(0,120);
|
| 135 |
+
opt.textContent = `[${i}] ${history[i].time} — ${p}`;
|
| 136 |
+
historySelect.appendChild(opt);
|
| 137 |
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
// append new history entry, keep newest first
|
| 141 |
+
function pushHistory(prompt, code){
|
| 142 |
+
const entry = { time: new Date().toLocaleString(), prompt: prompt, code: code };
|
| 143 |
+
history.unshift(entry);
|
| 144 |
+
if(history.length>200) history.pop();
|
| 145 |
+
saveLocalHistory(history);
|
| 146 |
+
refreshHistoryUI();
|
| 147 |
+
// notify backend to append persistent history (best-effort)
|
| 148 |
+
fetch('/run/history_append', {
|
| 149 |
+
method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({prompt:prompt, code:code})
|
| 150 |
+
}).catch(()=>{/* ignore errors */});
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
// ============ API helpers ============
|
| 154 |
+
async function apiPredict(prompt, max_tokens=512, temperature=0.2, top_p=0.9){
|
| 155 |
+
const body = { data: [prompt, max_tokens, temperature, top_p] };
|
| 156 |
+
const res = await fetch(PREDICT_URL, { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
| 157 |
+
if(!res.ok) throw new Error('Server error: '+res.status);
|
| 158 |
+
const j = await res.json();
|
| 159 |
+
return j?.data?.[0] ?? null;
|
| 160 |
+
}
|
| 161 |
+
async function apiExplain(code, max_tokens=512, temperature=0.2, top_p=0.9){
|
| 162 |
+
const body = { data: [code, max_tokens, temperature, top_p] };
|
| 163 |
+
const res = await fetch(EXPLAIN_URL, { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
| 164 |
+
if(!res.ok) throw new Error('Server error: '+res.status);
|
| 165 |
+
const j = await res.json();
|
| 166 |
+
return j?.data?.[0] ?? null;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// ============ UI events ============
|
| 170 |
+
generateBtn.addEventListener('click', async ()=>{
|
| 171 |
+
const prompt = promptEl.value.trim();
|
| 172 |
+
if(!prompt){ showToast('Enter a prompt first','error'); return; }
|
| 173 |
+
setLoading(generateBtn,true);
|
| 174 |
+
codeOutput.textContent = '// Generating…';
|
| 175 |
+
try{
|
| 176 |
+
const out = await apiPredict(prompt, 512, 0.2, 0.9);
|
| 177 |
+
codeOutput.textContent = out;
|
| 178 |
+
pushHistory(prompt, out);
|
| 179 |
+
showToast('Code generated');
|
| 180 |
+
}catch(err){
|
| 181 |
+
console.error(err);
|
| 182 |
+
codeOutput.textContent = '// Error generating code — check console';
|
| 183 |
+
showToast('Generation failed','error');
|
| 184 |
+
}finally{ setLoading(generateBtn,false); }
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
explainBtn.addEventListener('click', async ()=>{
|
| 188 |
+
const code = codeOutput.textContent || '';
|
| 189 |
+
if(!code){ showToast('No code to explain','error'); return; }
|
| 190 |
+
setLoading(explainBtn,true);
|
| 191 |
+
explanationContent.textContent = 'Explaining…';
|
| 192 |
+
try{
|
| 193 |
+
const out = await apiExplain(code, 512, 0.2, 0.9);
|
| 194 |
+
explanationContent.textContent = out;
|
| 195 |
+
explanationModal.classList.add('show');
|
| 196 |
+
}catch(err){
|
| 197 |
+
console.error(err);
|
| 198 |
+
explanationContent.textContent = 'Error explaining code';
|
| 199 |
+
}finally{ setLoading(explainBtn,false); }
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
clearBtn.addEventListener('click', ()=>{
|
| 203 |
+
promptEl.value=''; codeOutput.textContent='// Generated code will appear here';
|
| 204 |
+
showToast('Cleared');
|
| 205 |
+
});
|
| 206 |
+
|
| 207 |
+
copyBtn.addEventListener('click', async ()=>{
|
| 208 |
+
const code = codeOutput.textContent || '';
|
| 209 |
+
if(!code){ showToast('No code to copy','error'); return; }
|
| 210 |
+
try{ await navigator.clipboard.writeText(code); showToast('Copied to clipboard'); }catch(e){ showToast('Copy failed','error'); }
|
| 211 |
+
});
|
| 212 |
+
|
| 213 |
+
downloadBtn.addEventListener('click', ()=>{
|
| 214 |
+
const code = codeOutput.textContent || '';
|
| 215 |
+
if(!code){ showToast('No code to download','error'); return; }
|
| 216 |
+
const blob = new Blob([code], {type:'text/plain'}); const url = URL.createObjectURL(blob);
|
| 217 |
+
const a = document.createElement('a'); a.href=url; a.download='generated_code.py'; document.body.appendChild(a); a.click(); a.remove();
|
| 218 |
+
URL.revokeObjectURL(url);
|
| 219 |
+
showToast('Download started');
|
| 220 |
+
});
|
| 221 |
+
|
| 222 |
+
loadHistoryBtn.addEventListener('click', ()=>{
|
| 223 |
+
const idx = historySelect.value;
|
| 224 |
+
if(idx===''|| idx==null){ showToast('Pick a history item','error'); return; }
|
| 225 |
+
const entry = history[Number(idx)];
|
| 226 |
+
if(!entry){ showToast('Invalid index','error'); return; }
|
| 227 |
+
promptEl.value = entry.prompt;
|
| 228 |
+
codeOutput.textContent = entry.code;
|
| 229 |
+
showToast('Loaded from history');
|
| 230 |
+
});
|
| 231 |
+
|
| 232 |
+
clearHistoryBtn.addEventListener('click', ()=>{
|
| 233 |
+
if(!confirm('Clear local history?')) return;
|
| 234 |
+
history = []; saveLocalHistory(history); refreshHistoryUI();
|
| 235 |
+
fetch('/run/history_clear', {method:'POST'}).catch(()=>{/* ignore server errors */});
|
| 236 |
+
showToast('History cleared');
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
// modal close
|
| 240 |
+
closeModal.addEventListener('click', ()=> explanationModal.classList.remove('show'));
|
| 241 |
+
explanationModal.addEventListener('click', (e)=> { if(e.target===explanationModal) explanationModal.classList.remove('show'); });
|
| 242 |
+
|
| 243 |
+
// health ping (optional)
|
| 244 |
+
async function pingStatus(){
|
| 245 |
+
try{
|
| 246 |
+
const r = await fetch('/health'); if(r.ok){ const j = await r.json(); statusText.textContent = `status: ${j.status}`; }else{ statusText.textContent='status:down'; }
|
| 247 |
+
}catch(e){ statusText.textContent='status:down'; }
|
| 248 |
+
}
|
| 249 |
+
pingStatus();
|
| 250 |
+
</script>
|
| 251 |
</body>
|
| 252 |
+
</html>
|