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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
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Générateur de Données Synthétiques</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .container {
            background: white;
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            padding: 40px;
            max-width: 800px;
            width: 100%;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
        }

        .header h1 {
            color: #333;
            font-size: 2.5em;
            margin-bottom: 10px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .header p {
            color: #666;
            font-size: 1.1em;
        }

        .upload-section {
            border: 3px dashed #ddd;
            border-radius: 15px;
            padding: 40px;
            text-align: center;
            margin-bottom: 30px;
            transition: all 0.3s ease;
        }

        .upload-section:hover {
            border-color: #667eea;
            background: #f8f9ff;
        }

        .upload-section.dragover {
            border-color: #667eea;
            background: #f0f4ff;
        }

        input[type="file"] {
            display: none;
        }

        .upload-btn {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            padding: 15px 30px;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            font-size: 1.1em;
            font-weight: 600;
            transition: all 0.3s ease;
            margin: 10px;
        }

        .upload-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.2);
        }

        .progress-section {
            display: none;
            margin-top: 30px;
        }

        .progress-bar {
            width: 100%;
            height: 20px;
            background: #f0f0f0;
            border-radius: 10px;
            overflow: hidden;
            margin: 20px 0;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #667eea, #764ba2);
            width: 0%;
            transition: width 0.3s ease;
            position: relative;
        }

        .progress-fill::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
            animation: shimmer 2s infinite;
        }

        @keyframes shimmer {
            0% { transform: translateX(-100%); }
            100% { transform: translateX(100%); }
        }

        .status-info {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }

        .status-card {
            background: #f8f9ff;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            border-left: 4px solid #667eea;
        }

        .status-card h3 {
            color: #333;
            margin-bottom: 10px;
        }

        .status-card p {
            color: #666;
            font-size: 1.2em;
            font-weight: bold;
        }

        .download-btn {
            background: linear-gradient(135deg, #28a745, #20c997);
            color: white;
            padding: 15px 30px;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            font-size: 1.1em;
            font-weight: 600;
            transition: all 0.3s ease;
            margin: 20px 10px;
            display: none;
        }

        .download-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.2);
        }

        .tasks-section {
            margin-top: 30px;
            padding-top: 30px;
            border-top: 2px solid #eee;
        }

        .task-item {
            background: #f8f9ff;
            padding: 15px;
            border-radius: 10px;
            margin: 10px 0;
            border-left: 4px solid #667eea;
        }

        .task-item.completed {
            border-left-color: #28a745;
        }

        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 25px;
            border-radius: 10px;
            color: white;
            font-weight: 600;
            transform: translateX(100%);
            transition: transform 0.3s ease;
            z-index: 1000;
        }

        .notification.success {
            background: linear-gradient(135deg, #28a745, #20c997);
        }

        .notification.error {
            background: linear-gradient(135deg, #dc3545, #c82333);
        }

        .notification.show {
            transform: translateX(0);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🤖 Générateur de Données Synthétiques</h1>
            <p>Uploadez votre fichier pour générer 470 jeux de données synthétiques</p>
        </div>

        <div class="upload-section" id="uploadSection">
            <h3>📁 Sélectionnez votre fichier</h3>
            <p>Glissez-déposez votre fichier ici ou cliquez pour sélectionner</p>
            <input type="file" id="fileInput" accept=".txt">
            <button class="upload-btn" onclick="document.getElementById('fileInput').click()">
                Choisir le fichier
            </button>
            <button class="upload-btn" id="startBtn" onclick="startGeneration()" style="display: none;">
                🚀 Démarrer la génération
            </button>
        </div>

        <div class="progress-section" id="progressSection">
            <h3>⏳ Génération en cours...</h3>
            <div class="progress-bar">
                <div class="progress-fill" id="progressFill"></div>
            </div>
            <div class="status-info">
                <div class="status-card">
                    <h3>Progrès</h3>
                    <p id="progressText">0 / 470</p>
                </div>
                <div class="status-card">
                    <h3>Pourcentage</h3>
                    <p id="percentageText">0%</p>
                </div>
                <div class="status-card">
                    <h3>Statut</h3>
                    <p id="statusText">En attente</p>
                </div>
                <div class="status-card">
                    <h3>Heure de début</h3>
                    <p id="startTimeText">-</p>
                </div>
            </div>
            
            <button class="download-btn" id="downloadBtn" onclick="downloadResults()">
                📥 Télécharger les résultats
            </button>
        </div>

        <div class="tasks-section">
            <h3>📋 Tâches précédentes</h3>
            <div id="tasksList"></div>
        </div>
    </div>

    <div class="notification" id="notification"></div>

    <script>
        let currentTaskId = null;
        let statusInterval = null;

        // Gestion du drag & drop
        const uploadSection = document.getElementById('uploadSection');
        const fileInput = document.getElementById('fileInput');

        uploadSection.addEventListener('dragover', (e) => {
            e.preventDefault();
            uploadSection.classList.add('dragover');
        });

        uploadSection.addEventListener('dragleave', () => {
            uploadSection.classList.remove('dragover');
        });

        uploadSection.addEventListener('drop', (e) => {
            e.preventDefault();
            uploadSection.classList.remove('dragover');
            
            const files = e.dataTransfer.files;
            if (files.length > 0) {
                fileInput.files = files;
                handleFileSelect();
            }
        });

        fileInput.addEventListener('change', handleFileSelect);

        function handleFileSelect() {
            const file = fileInput.files[0];
            if (file) {
                document.getElementById('startBtn').style.display = 'inline-block';
                showNotification(`Fichier sélectionné: ${file.name}`, 'success');
            }
        }

        function startGeneration() {
            const file = fileInput.files[0];
            if (!file) {
                showNotification('Veuillez sélectionner un fichier', 'error');
                return;
            }

            const formData = new FormData();
            formData.append('file', file);

            fetch('/upload', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.error) {
                    showNotification(data.error, 'error');
                } else {
                    currentTaskId = data.task_id;
                    document.getElementById('progressSection').style.display = 'block';
                    startStatusPolling();
                    showNotification('Génération démarrée!', 'success');
                }
            })
            .catch(error => {
                showNotification('Erreur lors du démarrage', 'error');
                console.error('Error:', error);
            });
        }

        function startStatusPolling() {
            if (statusInterval) clearInterval(statusInterval);
            
            statusInterval = setInterval(() => {
                if (currentTaskId) {
                    fetch(`/status/${currentTaskId}`)
                    .then(response => response.json())
                    .then(data => {
                        updateProgress(data);
                        if (data.status === 'completed') {
                            clearInterval(statusInterval);
                            document.getElementById('downloadBtn').style.display = 'inline-block';
                            showNotification('Génération terminée!', 'success');
                        }
                    })
                    .catch(console.error);
                }
            }, 2000);
        }

        function updateProgress(data) {
            const progressFill = document.getElementById('progressFill');
            const progressText = document.getElementById('progressText');
            const percentageText = document.getElementById('percentageText');
            const statusText = document.getElementById('statusText');
            const startTimeText = document.getElementById('startTimeText');

            progressFill.style.width = `${data.percentage}%`;
            progressText.textContent = `${data.progress} / ${data.total}`;
            percentageText.textContent = `${data.percentage}%`;
            statusText.textContent = data.status === 'running' ? 'En cours' : 
                                   data.status === 'completed' ? 'Terminé' : data.status;
            startTimeText.textContent = data.start_time;
        }

        function downloadResults() {
            if (currentTaskId) {
                window.location.href = `/download/${currentTaskId}`;
            }
        }

        function showNotification(message, type) {
            const notification = document.getElementById('notification');
            notification.textContent = message;
            notification.className = `notification ${type}`;
            notification.classList.add('show');

            setTimeout(() => {
                notification.classList.remove('show');
            }, 3000);
        }

        function loadTasks() {
            fetch('/tasks')
            .then(response => response.json())
            .then(tasks => {
                const tasksList = document.getElementById('tasksList');
                tasksList.innerHTML = '';

                tasks.forEach(task => {
                    const taskItem = document.createElement('div');
                    taskItem.className = `task-item ${task.status}`;
                    taskItem.innerHTML = `
                        <div style="display: flex; justify-content: space-between; align-items: center;">
                            <div>
                                <strong>Tâche ${task.id.substring(0, 8)}...</strong><br>
                                <small>Démarré: ${task.start_time} | Progrès: ${task.progress}/${task.total} (${task.percentage}%)</small>
                            </div>
                            <div>
                                ${task.status === 'completed' ? 
                                    `<button class="download-btn" style="display: inline-block; margin: 0;" onclick="window.location.href='/download/${task.id}'">Télécharger</button>` : 
                                    `<span style="color: #667eea; font-weight: bold;">${task.status}</span>`
                                }
                            </div>
                        </div>
                    `;
                    tasksList.appendChild(taskItem);
                });
            })
            .catch(console.error);
        }

        // Charger les tâches au démarrage
        loadTasks();

        // Recharger les tâches toutes les 30 secondes
        setInterval(loadTasks, 30000);
    </script>
</body>
</html>