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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
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
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gradio Context & Dockerizer</title>
    <!-- Importing Phosphor Icons for modern UI iconography -->
    <script src="https://unpkg.com/@phosphor-icons/web"></script>
    
    <style>
        /* --- CSS VARIABLES & RESET --- */
        :root {
            --bg-body: #0f1115;
            --bg-panel: #161b22;
            --bg-input: #0d1117;
            --border-color: #30363d;
            --primary: #238636;
            --primary-hover: #2ea043;
            --accent: #58a6ff;
            --text-main: #c9d1d9;
            --text-muted: #8b949e;
            --font-stack: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
            --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
            --radius-md: 8px;
            --radius-lg: 12px;
            --shadow: 0 4px 12px rgba(0,0,0,0.5);
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            background-color: var(--bg-body);
            color: var(--text-main);
            font-family: var(--font-stack);
            height: 100vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* --- HEADER --- */
        header {
            height: 60px;
            background-color: var(--bg-panel);
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 20px;
            flex-shrink: 0;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 10px;
            font-weight: 600;
            font-size: 1.1rem;
        }

        .brand i {
            color: var(--accent);
            font-size: 1.4rem;
        }

        .anycoder-link {
            font-size: 0.85rem;
            color: var(--text-muted);
            text-decoration: none;
            background: rgba(255,255,255,0.05);
            padding: 6px 12px;
            border-radius: 20px;
            transition: all 0.2s;
            border: 1px solid transparent;
        }

        .anycoder-link:hover {
            color: var(--accent);
            border-color: var(--border-color);
            background: rgba(255,255,255,0.1);
        }

        /* --- LAYOUT --- */
        .layout {
            display: grid;
            grid-template-columns: 320px 1fr;
            flex: 1;
            overflow: hidden;
        }

        /* --- SIDEBAR (CONFIGURATION) --- */
        aside {
            background-color: var(--bg-panel);
            border-right: 1px solid var(--border-color);
            padding: 20px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 24px;
        }

        .config-group h3 {
            font-size: 0.8rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-muted);
            margin-bottom: 12px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .form-control {
            margin-bottom: 16px;
        }

        .form-control label {
            display: block;
            font-size: 0.9rem;
            margin-bottom: 6px;
            color: var(--text-main);
        }

        .form-control input[type="text"],
        .form-control select,
        .form-control textarea {
            width: 100%;
            background-color: var(--bg-input);
            border: 1px solid var(--border-color);
            color: var(--text-main);
            padding: 8px 12px;
            border-radius: var(--radius-md);
            font-family: inherit;
            font-size: 0.9rem;
            transition: border-color 0.2s;
        }

        .form-control input:focus,
        .form-control select:focus,
        .form-control textarea:focus {
            outline: none;
            border-color: var(--accent);
        }

        .range-wrapper {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .range-wrapper input {
            flex: 1;
        }

        .range-value {
            font-family: var(--font-mono);
            font-size: 0.85rem;
            color: var(--accent);
            width: 30px;
            text-align: right;
        }

        /* --- MAIN CONTENT AREA --- */
        main {
            padding: 20px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 20px;
            background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
            background-size: 24px 24px;
        }

        .card {
            background-color: var(--bg-panel);
            border: 1px solid var(--border-color);
            border-radius: var(--radius-lg);
            padding: 20px;
            box-shadow: var(--shadow);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 12px;
        }

        .card-title {
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        /* --- DOCKERFILE PREVIEW --- */
        .code-block {
            background-color: #0d1117;
            border-radius: var(--radius-md);
            padding: 16px;
            font-family: var(--font-mono);
            font-size: 0.85rem;
            color: #a5d6ff;
            overflow-x: auto;
            white-space: pre;
            position: relative;
        }

        .copy-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(255,255,255,0.1);
            border: none;
            color: var(--text-main);
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.75rem;
            cursor: pointer;
            opacity: 0;
            transition: opacity 0.2s;
        }

        .code-block:hover .copy-btn {
            opacity: 1;
        }

        /* --- TERMINAL / LOGS --- */
        .terminal {
            background-color: #000;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            padding: 12px;
            font-family: var(--font-mono);
            font-size: 0.85rem;
            height: 200px;
            overflow-y: auto;
            color: #d2a8ff;
        }

        .log-line {
            margin-bottom: 4px;
            display: flex;
            gap: 8px;
        }

        .log-time {
            color: var(--text-muted);
        }

        .log-success { color: var(--primary); }
        .log-info { color: var(--accent); }
        .log-warn { color: #d29922; }

        /* --- ACTION BUTTONS --- */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 10px 20px;
            border-radius: var(--radius-md);
            font-weight: 600;
            cursor: pointer;
            border: none;
            transition: all 0.2s;
            font-size: 0.95rem;
        }

        .btn-primary {
            background-color: var(--primary);
            color: white;
        }

        .btn-primary:hover {
            background-color: var(--primary-hover);
        }

        .btn-primary:disabled {
            background-color: #23863680;
            cursor: not-allowed;
        }

        .btn-secondary {
            background-color: transparent;
            border: 1px solid var(--border-color);
            color: var(--text-main);
        }

        .btn-secondary:hover {
            border-color: var(--text-muted);
            background-color: rgba(255,255,255,0.05);
        }

        /* --- GRADIO PREVIEW --- */
        .gradio-sim {
            border: 2px dashed var(--border-color);
            border-radius: var(--radius-lg);
            padding: 30px;
            text-align: center;
            color: var(--text-muted);
            position: relative;
            background: rgba(255,255,255,0.02);
        }

        .gradio-active {
            border-style: solid;
            border-color: var(--accent);
            background: rgba(88, 166, 255, 0.05);
            color: var(--text-main);
        }

        .status-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.75rem;
            font-weight: 600;
            background: rgba(110, 118, 129, 0.2);
        }

        .status-running {
            background: rgba(46, 160, 67, 0.2);
            color: #3fb950;
        }

        /* --- RESPONSIVE --- */
        @media (max-width: 768px) {
            .layout {
                grid-template-columns: 1fr;
                grid-template-rows: auto 1fr;
            }
            aside {
                border-right: none;
                border-bottom: 1px solid var(--border-color);
                max-height: 300px;
            }
        }
    </style>
</head>
<body>

    <header>
        <div class="brand">
            <i class="ph ph-cube-transparent"></i>
            <span>AutoDockerizer</span>
        </div>
        <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">
            Built with anycoder <i class="ph ph-arrow-up-right"></i>
        </a>
    </header>

    <div class="layout">
        <!-- SIDEBAR: CONFIGURATION -->
        <aside>
            <div class="config-group">
                <h3><i class="ph ph-gear"></i> Environment</h3>
                <div class="form-control">
                    <label>Python Version</label>
                    <select id="pythonVersion">
                        <option value="3.10">Python 3.10</option>
                        <option value="3.11" selected>Python 3.11</option>
                        <option value="3.12">Python 3.12</option>
                    </select>
                </div>
                <div class="form-control">
                    <label>Base Image</label>
                    <select id="baseImage">
                        <option value="python/slim">Python Slim</option>
                        <option value="nvidia/cuda">CUDA (GPU)</option>
                        <option value="ubuntu">Ubuntu Latest</option>
                    </select>
                </div>
            </div>

            <div class="config-group">
                <h3><i class="ph ph-brackets-curly"></i> Gradio Config</h3>
                <div class="form-control">
                    <label>App Title</label>
                    <input type="text" id="appTitle" value="My AI Demo">
                </div>
                <div class="form-control">
                    <label>Model ID (Hugging Face)</label>
                    <input type="text" id="modelId" placeholder="e.g. gpt2">
                </div>
            </div>

            <div class="config-group">
                <h3><i class="ph ph-sliders"></i> Parameters</h3>
                <div class="form-control">
                    <label>Max Tokens</label>
                    <div class="range-wrapper">
                        <input type="range" min="64" max="4096" value="512" id="maxTokens">
                        <span class="range-value" id="val-maxTokens">512</span>
                    </div>
                </div>
                <div class="form-control">
                    <label>Temperature</label>
                    <div class="range-wrapper">
                        <input type="range" min="0" max="1" step="0.1" value="0.7" id="temperature">
                        <span class="range-value" id="val-temperature">0.7</span>
                    </div>
                </div>
            </div>

            <div class="config-group">
                <h3><i class="ph ph-file-code"></i> Actions</h3>
                <button class="btn btn-primary" style="width: 100%" onclick="runDeployment()">
                    <i class="ph ph-rocket-launch"></i> Build & Deploy
                </button>
            </div>
        </aside>

        <!-- MAIN CONTENT -->
        <main>
            <!-- Dockerfile Preview -->
            <section class="card">
                <div class="card-header">
                    <div class="card-title">
                        <i class="ph ph-docker-logo"></i> Generated Dockerfile
                    </div>
                    <div class="status-badge">Auto-generated</div>
                </div>
                <div class="code-block" id="dockerfileOutput">
                    <button class="copy-btn" onclick="copyDockerfile()">Copy</button>
                    <!-- Content injected via JS -->
                </div>
            </section>

            <!-- Terminal & Status -->
            <section class="card">
                <div class="card-header">
                    <div class="card-title">
                        <i class="ph ph-terminal-window"></i> Build Terminal
                    </div>
                    <div id="buildStatus" class="status-badge">Waiting for input...</div>
                </div>
                <div class="terminal" id="terminalOutput">
                    <div class="log-line"><span class="log-time">[System]</span> Ready to initialize build process.</div>
                </div>
            </section>

            <!-- Gradio Simulation -->
            <section class="card">
                <div class="card-header">
                    <div class="card-title">
                        <i class="ph ph-monitor-play"></i> Gradio Live Preview
                    </div>
                </div>
                <div class="gradio-sim" id="gradioPreview">
                    <i class="ph ph-cloud-arrow-up" style="font-size: 3rem; margin-bottom: 10px; display: block;"></i>
                    <p>Click "Build & Deploy" to start the container and launch the Gradio interface.</p>
                    <div style="margin-top: 15px; opacity: 0.5; font-size: 0.8rem;">
                        Running on http://127.0.0.1:7860
                    </div>
                </div>
            </section>
        </main>
    </div>

    <script>
        // --- DOM ELEMENTS ---
        const inputs = {
            python: document.getElementById('pythonVersion'),
            base: document.getElementById('baseImage'),
            title: document.getElementById('appTitle'),
            model: document.getElementById('modelId'),
            tokens: document.getElementById('maxTokens'),
            temp: document.getElementById('temperature')
        };

        const displays = {
            tokens: document.getElementById('val-maxTokens'),
            temp: document.getElementById('val-temperature')
        };

        const outputs = {
            dockerfile: document.getElementById('dockerfileOutput'),
            terminal: document.getElementById('terminalOutput'),
            status: document.getElementById('buildStatus'),
            preview: document.getElementById('gradioPreview')
        };

        // --- EVENT LISTENERS FOR LIVE UPDATES ---
        Object.values(inputs).forEach(input => {
            input.addEventListener('input', updateDockerfile);
        });

        // Update slider values immediately
        inputs.tokens.addEventListener('input', (e) => displays.tokens.textContent = e.target.value);
        inputs.temp.addEventListener('input', (e) => displays.temp.textContent = e.target.value);

        // --- CORE FUNCTIONS ---

        function updateDockerfile() {
            const pyVer = inputs.python.value;
            const base = inputs.base.value;
            const title = inputs.title.value || 'My AI Demo';
            const model = inputs.model.value || 'gpt2';
            
            // Logic to select appropriate base image string
            let fromString = `python:${pyVer}-slim`;
            if (base.includes('cuda')) fromString = `nvidia/cuda:11.8.0-runtime-ubuntu${pyVer > 11 ? '22.04' : '20.04'}`;
            if (base.includes('ubuntu')) fromString = `ubuntu:latest`;

            const dockerfileContent = `# Auto-generated Dockerfile for Gradio App
FROM ${fromString}

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \\
    git \\
    git-lfs \\
    && rm -rf /var/lib/apt/lists/*

# Copy requirements file (simulated)
RUN pip install --no-cache-dir -U pip
RUN pip install gradio torch transformers accelerate

# Set environment variables
ENV MODEL_ID="${model}"
ENV MAX_TOKENS=${inputs.tokens.value}
ENV TEMPERATURE=${inputs.temp.value}
APP_TITLE="${title}"

# Copy application code
COPY app.py .

# Expose port
EXPOSE 7860

# Run Gradio app
CMD ["python", "app.py"]
`;

            // Preserve the copy button, replace text content
            const btn = outputs.dockerfile.querySelector('.copy-btn');
            outputs.dockerfile.innerHTML = '';
            outputs.dockerfile.appendChild(btn);
            outputs.dockerfile.appendChild(document.createTextNode(dockerfileContent));
        }

        function copyDockerfile() {
            const text = outputs.dockerfile.textContent.replace('Copy', '').trim();
            navigator.clipboard.writeText(text).then(() => {
                const btn = outputs.dockerfile.querySelector('.copy-btn');
                const originalText = btn.textContent;
                btn.textContent = 'Copied!';
                setTimeout(() => btn.textContent = originalText, 2000);
            });
        }

        function addLog(message, type = 'info') {
            const line = document.createElement('div');
            line.className = 'log-line';
            
            const time = new Date().toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute:'2-digit', second:'2-digit' });
            
            let typeClass = 'log-info';
            if(type === 'success') typeClass = 'log-success';
            if(type === 'warn') typeClass = 'log-warn';

            line.innerHTML = `<span class="log-time">[${time}]</span> <span class="${typeClass}">${message}</span>`;
            outputs.terminal.appendChild(line);
            outputs.terminal.scrollTop = outputs.terminal.scrollHeight;
        }

        async function runDeployment() {
            // Reset state
            outputs.terminal.innerHTML = '';
            outputs.status.textContent = 'Building...';
            outputs.status.className = 'status-badge';
            outputs.preview.classList.remove('gradio-active');
            outputs.preview.innerHTML = `
                <i class="ph ph-spinner ph-spin" style="font-size: 3rem; margin-bottom: 10px; display: block;"></i>
                <p>Initializing Container...</p>
            `;

            const steps = [
                { msg: "Pulling base image...", delay: 800 },
                { msg: "Installing system dependencies (git, lfs)...", delay: 1500 },
                { msg: "Upgrading pip...", delay: 1000 },
                { msg: "Installing Python packages (gradio, torch)...", delay: 2500 },
                { msg: "Downloading model weights...", delay: 2000 },
                { msg: "Exposing port 7860...", delay: 500 },
                { msg: "Starting Gradio interface...", delay: 800, type: 'success' }
            ];

            for (let step of steps) {
                await new Promise(r => setTimeout(r, step.delay));
                addLog(step.msg, step.type || 'info');
            }

            // Final State
            outputs.status.textContent = 'Running';
            outputs.status.className = 'status-badge status-running';
            
            // Update Preview UI
            const title = inputs.title.value;
            outputs.preview.classList.add('gradio-active');
            outputs.preview.innerHTML = `
                <div style="text-align: left; max-width: 600px; margin: 0 auto;">
                    <h2 style="margin-bottom: 20px; color: var(--accent);">${title}</h2>
                    <div style="background: var(--bg-input); padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); margin-bottom: 15px;">
                        <label style="display:block; margin-bottom:5px; font-size:0.8rem;">Input Prompt</label>
                        <input type="text" placeholder="Type something here..." style="width:100%; background:transparent; border:none; color:white; outline:none;">
                    </div>
                    <button class="btn btn-secondary" style="width:100%;">Submit</button>
                    <div style="margin-top: 20px; padding: 15px; background: rgba(46, 160, 67, 0.1); border: 1px solid var(--primary); border-radius: 8px; color: var(--primary);">
                        <i class="ph ph-check-circle"></i> Output will appear here.
                    </div>
                </div>
                <div style="margin-top: 20px; font-size: 0.8rem; color: var(--text-muted);">
                    <i class="ph ph-share-network"></i> Public URL: https://huggingface.co/spaces/user/${title.replace(/\s+/g, '-').toLowerCase()}
                </div>
            `;
            
            addLog("Application successfully deployed.", "success");
        }

        // Initialize on load
        updateDockerfile();

    </script>
</body>
</html>