Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +559 -668
index.html
CHANGED
|
@@ -1,669 +1,560 @@
|
|
| 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.0">
|
| 6 |
-
<title>AI Code Assistant</title>
|
| 7 |
-
<style>
|
| 8 |
-
* {
|
| 9 |
-
margin: 0;
|
| 10 |
-
padding: 0;
|
| 11 |
-
box-sizing: border-box;
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
body {
|
| 15 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 16 |
-
background-color: #f9fafb;
|
| 17 |
-
min-height: 100vh;
|
| 18 |
-
padding: 2rem 1rem;
|
| 19 |
-
line-height: 1.6;
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
.container {
|
| 23 |
-
max-width: 64rem;
|
| 24 |
-
margin: 0 auto;
|
| 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 |
-
<div class="container">
|
| 335 |
-
<!-- Header -->
|
| 336 |
-
<div class="header">
|
| 337 |
-
<h1>AI Code Assistant</h1>
|
| 338 |
-
<p>Generate, explain, and manage your code with AI assistance</p>
|
| 339 |
-
</div>
|
| 340 |
-
|
| 341 |
-
<!-- Input Section -->
|
| 342 |
-
<div class="card">
|
| 343 |
-
<div class="form-group">
|
| 344 |
-
<label for="prompt" class="form-label">
|
| 345 |
-
Enter your coding question or prompt:
|
| 346 |
-
</label>
|
| 347 |
-
<textarea
|
| 348 |
-
id="prompt"
|
| 349 |
-
class="textarea"
|
| 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 |
-
<!-- Explanation Modal -->
|
| 397 |
-
<div id="explanationModal" class="modal">
|
| 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 |
-
<!-- Toast Notification -->
|
| 414 |
-
<div id="toast" class="toast">
|
| 415 |
-
<span id="toastMessage">Code copied to clipboard!</span>
|
| 416 |
-
</div>
|
| 417 |
-
|
| 418 |
-
<script>
|
| 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 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
function showToast(message, type = 'success') {
|
| 561 |
-
toastMessage.textContent = message;
|
| 562 |
-
toast.className = `toast ${type}`;
|
| 563 |
-
toast.classList.add('show');
|
| 564 |
-
|
| 565 |
-
setTimeout(() => {
|
| 566 |
-
toast.classList.remove('show');
|
| 567 |
-
}, 3000);
|
| 568 |
-
}
|
| 569 |
-
|
| 570 |
-
function generateSampleCode(prompt) {
|
| 571 |
-
const lowerPrompt = prompt.toLowerCase();
|
| 572 |
-
|
| 573 |
-
if (lowerPrompt.includes('fibonacci')) {
|
| 574 |
-
return `def fibonacci(n):
|
| 575 |
-
"""Generate fibonacci sequence up to n terms."""
|
| 576 |
-
if n <= 0:
|
| 577 |
-
return []
|
| 578 |
-
elif n == 1:
|
| 579 |
-
return [0]
|
| 580 |
-
elif n == 2:
|
| 581 |
-
return [0, 1]
|
| 582 |
-
|
| 583 |
-
sequence = [0, 1]
|
| 584 |
-
for i in range(2, n):
|
| 585 |
-
sequence.append(sequence[i-1] + sequence[i-2])
|
| 586 |
-
|
| 587 |
-
return sequence
|
| 588 |
-
|
| 589 |
-
# Example usage
|
| 590 |
-
print(fibonacci(10))
|
| 591 |
-
# Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]`;
|
| 592 |
-
} else if (lowerPrompt.includes('sort')) {
|
| 593 |
-
return `def bubble_sort(arr):
|
| 594 |
-
"""Sort array using bubble sort algorithm."""
|
| 595 |
-
n = len(arr)
|
| 596 |
-
for i in range(n):
|
| 597 |
-
for j in range(0, n - i - 1):
|
| 598 |
-
if arr[j] > arr[j + 1]:
|
| 599 |
-
arr[j], arr[j + 1] = arr[j + 1], arr[j]
|
| 600 |
-
return arr
|
| 601 |
-
|
| 602 |
-
# Example usage
|
| 603 |
-
numbers = [64, 34, 25, 12, 22, 11, 90]
|
| 604 |
-
sorted_numbers = bubble_sort(numbers.copy())
|
| 605 |
-
print(f"Original: {numbers}")
|
| 606 |
-
print(f"Sorted: {sorted_numbers}")`;
|
| 607 |
-
} else if (lowerPrompt.includes('calculator')) {
|
| 608 |
-
return `class Calculator:
|
| 609 |
-
"""A simple calculator class."""
|
| 610 |
-
|
| 611 |
-
def add(self, a, b):
|
| 612 |
-
return a + b
|
| 613 |
-
|
| 614 |
-
def subtract(self, a, b):
|
| 615 |
-
return a - b
|
| 616 |
-
|
| 617 |
-
def multiply(self, a, b):
|
| 618 |
-
return a * b
|
| 619 |
-
|
| 620 |
-
def divide(self, a, b):
|
| 621 |
-
if b == 0:
|
| 622 |
-
raise ValueError("Cannot divide by zero")
|
| 623 |
-
return a / b
|
| 624 |
-
|
| 625 |
-
# Example usage
|
| 626 |
-
calc = Calculator()
|
| 627 |
-
print(f"5 + 3 = {calc.add(5, 3)}")
|
| 628 |
-
print(f"10 - 4 = {calc.subtract(10, 4)}")
|
| 629 |
-
print(f"6 * 7 = {calc.multiply(6, 7)}")
|
| 630 |
-
print(f"15 / 3 = {calc.divide(15, 3)}")`;
|
| 631 |
-
} else {
|
| 632 |
-
return `def hello_world():
|
| 633 |
-
"""A simple hello world function."""
|
| 634 |
-
message = "Hello, World!"
|
| 635 |
-
print(message)
|
| 636 |
-
return message
|
| 637 |
-
|
| 638 |
-
# Example usage
|
| 639 |
-
result = hello_world()
|
| 640 |
-
print(f"Function returned: {result}")
|
| 641 |
-
|
| 642 |
-
# Additional functionality
|
| 643 |
-
def greet_user(name):
|
| 644 |
-
"""Greet a specific user."""
|
| 645 |
-
greeting = f"Hello, {name}!"
|
| 646 |
-
print(greeting)
|
| 647 |
-
return greeting
|
| 648 |
-
|
| 649 |
-
# Example with user input
|
| 650 |
-
user_greeting = greet_user("Python Developer")`;
|
| 651 |
-
}
|
| 652 |
-
}
|
| 653 |
-
|
| 654 |
-
function generateSampleExplanation(code) {
|
| 655 |
-
return `
|
| 656 |
-
<p><strong>Code Explanation:</strong></p>
|
| 657 |
-
<p>This code demonstrates a Python implementation with the following key components:</p>
|
| 658 |
-
<ul style="margin: 1rem 0; padding-left: 1.5rem;">
|
| 659 |
-
<li><strong>Function Definition:</strong> The function is defined with proper parameters and includes a docstring for documentation.</li>
|
| 660 |
-
<li><strong>Logic Implementation:</strong> The core algorithm is implemented with appropriate error handling and edge cases considered.</li>
|
| 661 |
-
<li><strong>Example Usage:</strong> The code includes practical examples showing how to use the function with sample data.</li>
|
| 662 |
-
<li><strong>Best Practices:</strong> The code follows Python naming conventions, includes comments, and demonstrates clean, readable structure.</li>
|
| 663 |
-
</ul>
|
| 664 |
-
<p>The implementation is efficient and follows Python best practices for readability and maintainability.</p>
|
| 665 |
-
`;
|
| 666 |
-
}
|
| 667 |
-
</script>
|
| 668 |
-
</body>
|
| 669 |
</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.0">
|
| 6 |
+
<title>AI Code Assistant</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
body {
|
| 15 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 16 |
+
background-color: #f9fafb;
|
| 17 |
+
min-height: 100vh;
|
| 18 |
+
padding: 2rem 1rem;
|
| 19 |
+
line-height: 1.6;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.container {
|
| 23 |
+
max-width: 64rem;
|
| 24 |
+
margin: 0 auto;
|
| 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 |
+
<div class="container">
|
| 335 |
+
<!-- Header -->
|
| 336 |
+
<div class="header">
|
| 337 |
+
<h1>AI Code Assistant</h1>
|
| 338 |
+
<p>Generate, explain, and manage your code with AI assistance</p>
|
| 339 |
+
</div>
|
| 340 |
+
|
| 341 |
+
<!-- Input Section -->
|
| 342 |
+
<div class="card">
|
| 343 |
+
<div class="form-group">
|
| 344 |
+
<label for="prompt" class="form-label">
|
| 345 |
+
Enter your coding question or prompt:
|
| 346 |
+
</label>
|
| 347 |
+
<textarea
|
| 348 |
+
id="prompt"
|
| 349 |
+
class="textarea"
|
| 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 |
+
<!-- Explanation Modal -->
|
| 397 |
+
<div id="explanationModal" class="modal">
|
| 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 |
+
<!-- Toast Notification -->
|
| 414 |
+
<div id="toast" class="toast">
|
| 415 |
+
<span id="toastMessage">Code copied to clipboard!</span>
|
| 416 |
+
</div>
|
| 417 |
+
|
| 418 |
+
<script>
|
| 419 |
+
const promptTextarea = document.getElementById('prompt');
|
| 420 |
+
const generateBtn = document.getElementById('generateBtn');
|
| 421 |
+
const explainBtn = document.getElementById('explainBtn');
|
| 422 |
+
const clearBtn = document.getElementById('clearBtn');
|
| 423 |
+
const copyBtn = document.getElementById('copyBtn');
|
| 424 |
+
const downloadBtn = document.getElementById('downloadBtn');
|
| 425 |
+
const codeOutput = document.getElementById('codeOutput');
|
| 426 |
+
const explanationModal = document.getElementById('explanationModal');
|
| 427 |
+
const explanationContent = document.getElementById('explanationContent');
|
| 428 |
+
const closeModal = document.getElementById('closeModal');
|
| 429 |
+
const toast = document.getElementById('toast');
|
| 430 |
+
const toastMessage = document.getElementById('toastMessage');
|
| 431 |
+
|
| 432 |
+
let currentCode = '';
|
| 433 |
+
|
| 434 |
+
// Backend API URL (your HF Space)
|
| 435 |
+
const API_URL = "https://Agasthya0-colabmind-coder-qlora.hf.space/run/predict";
|
| 436 |
+
|
| 437 |
+
// Generate Code
|
| 438 |
+
generateBtn.addEventListener('click', async () => {
|
| 439 |
+
const prompt = promptTextarea.value.trim();
|
| 440 |
+
if (!prompt) {
|
| 441 |
+
showToast('Please enter a prompt first!', 'error');
|
| 442 |
+
return;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
setLoading(generateBtn, true);
|
| 446 |
+
codeOutput.textContent = "⏳ Generating code...";
|
| 447 |
+
|
| 448 |
+
try {
|
| 449 |
+
const res = await fetch(API_URL, {
|
| 450 |
+
method: "POST",
|
| 451 |
+
headers: { "Content-Type": "application/json" },
|
| 452 |
+
body: JSON.stringify({ data: [prompt] })
|
| 453 |
+
});
|
| 454 |
+
|
| 455 |
+
const result = await res.json();
|
| 456 |
+
currentCode = result?.data?.[0] || "⚠️ No output from backend.";
|
| 457 |
+
codeOutput.textContent = currentCode;
|
| 458 |
+
showToast('Code generated successfully!', 'success');
|
| 459 |
+
} catch (err) {
|
| 460 |
+
console.error(err);
|
| 461 |
+
showToast('Backend error: Could not generate code.', 'error');
|
| 462 |
+
codeOutput.textContent = "// Error generating code";
|
| 463 |
+
} finally {
|
| 464 |
+
setLoading(generateBtn, false);
|
| 465 |
+
}
|
| 466 |
+
});
|
| 467 |
+
|
| 468 |
+
// Explain Code
|
| 469 |
+
explainBtn.addEventListener('click', async () => {
|
| 470 |
+
if (!currentCode) {
|
| 471 |
+
showToast('No code to explain. Generate code first!', 'error');
|
| 472 |
+
return;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
setLoading(explainBtn, true);
|
| 476 |
+
explanationContent.textContent = "⏳ Explaining code...";
|
| 477 |
+
|
| 478 |
+
try {
|
| 479 |
+
const res = await fetch(API_URL, {
|
| 480 |
+
method: "POST",
|
| 481 |
+
headers: { "Content-Type": "application/json" },
|
| 482 |
+
body: JSON.stringify({ data: [`Explain this code:\n\n${currentCode}`] })
|
| 483 |
+
});
|
| 484 |
+
|
| 485 |
+
const result = await res.json();
|
| 486 |
+
explanationContent.textContent = result?.data?.[0] || "⚠️ No explanation returned.";
|
| 487 |
+
explanationModal.classList.add('show');
|
| 488 |
+
} catch (err) {
|
| 489 |
+
console.error(err);
|
| 490 |
+
explanationContent.textContent = "❌ Error explaining code.";
|
| 491 |
+
} finally {
|
| 492 |
+
setLoading(explainBtn, false);
|
| 493 |
+
}
|
| 494 |
+
});
|
| 495 |
+
|
| 496 |
+
// Clear
|
| 497 |
+
clearBtn.addEventListener('click', () => {
|
| 498 |
+
promptTextarea.value = '';
|
| 499 |
+
currentCode = '';
|
| 500 |
+
codeOutput.textContent = '// Your generated code will appear here...';
|
| 501 |
+
showToast('Cleared successfully!', 'success');
|
| 502 |
+
});
|
| 503 |
+
|
| 504 |
+
// Copy Code
|
| 505 |
+
copyBtn.addEventListener('click', async () => {
|
| 506 |
+
if (!currentCode) {
|
| 507 |
+
showToast('No code to copy!', 'error');
|
| 508 |
+
return;
|
| 509 |
+
}
|
| 510 |
+
await navigator.clipboard.writeText(currentCode);
|
| 511 |
+
showToast('Code copied to clipboard!', 'success');
|
| 512 |
+
});
|
| 513 |
+
|
| 514 |
+
// Download Code
|
| 515 |
+
downloadBtn.addEventListener('click', () => {
|
| 516 |
+
if (!currentCode) {
|
| 517 |
+
showToast('No code to download!', 'error');
|
| 518 |
+
return;
|
| 519 |
+
}
|
| 520 |
+
const blob = new Blob([currentCode], { type: 'text/plain' });
|
| 521 |
+
const url = URL.createObjectURL(blob);
|
| 522 |
+
const a = document.createElement('a');
|
| 523 |
+
a.href = url;
|
| 524 |
+
a.download = 'generated_code.py';
|
| 525 |
+
document.body.appendChild(a);
|
| 526 |
+
a.click();
|
| 527 |
+
document.body.removeChild(a);
|
| 528 |
+
URL.revokeObjectURL(url);
|
| 529 |
+
});
|
| 530 |
+
|
| 531 |
+
// Modal
|
| 532 |
+
closeModal.addEventListener('click', () => {
|
| 533 |
+
explanationModal.classList.remove('show');
|
| 534 |
+
});
|
| 535 |
+
explanationModal.addEventListener('click', (e) => {
|
| 536 |
+
if (e.target === explanationModal) {
|
| 537 |
+
explanationModal.classList.remove('show');
|
| 538 |
+
}
|
| 539 |
+
});
|
| 540 |
+
|
| 541 |
+
// Utils
|
| 542 |
+
function setLoading(button, isLoading) {
|
| 543 |
+
if (isLoading) {
|
| 544 |
+
button.disabled = true;
|
| 545 |
+
button.setAttribute('data-original', button.innerHTML);
|
| 546 |
+
button.innerHTML = `<div class="spinner"></div> Loading...`;
|
| 547 |
+
} else {
|
| 548 |
+
button.disabled = false;
|
| 549 |
+
button.innerHTML = button.getAttribute('data-original');
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
function showToast(message, type = 'success') {
|
| 553 |
+
toastMessage.textContent = message;
|
| 554 |
+
toast.className = `toast ${type} show`;
|
| 555 |
+
setTimeout(() => toast.classList.remove('show'), 3000);
|
| 556 |
+
}
|
| 557 |
+
</script>
|
| 558 |
+
|
| 559 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
</html>
|