File size: 13,235 Bytes
f9726ec
1f7f905
236c7d2
 
 
92be86b
236c7d2
1f7f905
 
92be86b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f7f905
92be86b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f7f905
92be86b
 
 
 
 
 
 
 
1f7f905
92be86b
 
1f7f905
 
 
92be86b
1f7f905
92be86b
1f7f905
 
 
92be86b
1f7f905
92be86b
 
 
 
 
 
 
 
 
 
1f7f905
9f4c5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
f9726ec
 
 
 
 
1f7f905
236c7d2
92be86b
 
 
 
 
 
1f7f905
236c7d2
9f4c5c8
1f7f905
92be86b
9f4c5c8
92be86b
 
 
 
 
1f7f905
92be86b
 
1f7f905
61a8581
9f4c5c8
 
 
1f7f905
 
92be86b
 
1f7f905
 
 
92be86b
 
 
 
1f7f905
61a8581
236c7d2
92be86b
 
 
 
 
1f7f905
 
 
f9726ec
 
1f7f905
 
61a8581
92be86b
 
 
61a8581
236c7d2
 
 
 
 
1f7f905
 
 
 
9f4c5c8
1f7f905
 
 
 
9f4c5c8
 
236c7d2
1f7f905
 
 
 
236c7d2
f9726ec
92be86b
9f4c5c8
 
 
 
 
 
 
 
 
 
 
92be86b
 
 
f9726ec
92be86b
9f4c5c8
92be86b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f4c5c8
 
 
f9726ec
 
9f4c5c8
 
 
 
 
 
 
 
 
 
 
 
 
f9726ec
1f7f905
 
 
 
 
 
 
236c7d2
f9726ec
1f7f905
9f4c5c8
 
 
f9726ec
61a8581
1f7f905
 
236c7d2
1f7f905
f9726ec
1f7f905
 
f9726ec
1f7f905
9f4c5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9726ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f4c5c8
 
 
1f7f905
9f4c5c8
61a8581
1f7f905
9f4c5c8
 
1f7f905
 
 
236c7d2
 
 
 
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
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mariam M-0 | Solution Mathématique</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_HTML"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

        body {
            font-family: 'Space Grotesk', sans-serif;
            background: linear-gradient(125deg, #000428 0%, #004e92 100%);
            min-height: 100vh;
        }

        .glass-card {
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
        }

        .uploadArea {
            background: linear-gradient(145deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
            border: 2px dashed rgba(255, 255, 255, 0.2);
        }

        .uploadArea:hover {
            border-color: #60A5FA;
            transform: translateY(-2px);
        }

        .neon-button {
            background: linear-gradient(90deg, #4F46E5 0%, #60A5FA 100%);
            box-shadow: 0 0 15px rgba(79, 70, 229, 0.5);
            transition: all 0.3s ease;
        }

        .neon-button:hover {
            box-shadow: 0 0 25px rgba(79, 70, 229, 0.7);
            transform: translateY(-2px);
        }

        .loader {
            width: 48px;
            height: 48px;
            border: 3px solid #FFF;
            border-bottom-color: transparent;
            border-radius: 50%;
            display: inline-block;
            box-sizing: border-box;
            animation: rotation 1s linear infinite;
        }

        @keyframes rotation {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .thought-box {
            transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
            max-height: 0;
            overflow: hidden;
        }

        .thought-box.open {
            max-height: 1000px;
        }

        .glow {
            animation: glow 2s ease-in-out infinite alternate;
        }

        @keyframes glow {
            from { text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #60A5FA; }
            to { text-shadow: 0 0 20px #fff, 0 0 30px #4F46E5, 0 0 40px #4F46E5; }
        }

        .preview-container {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 20px;
        }
    
        .preview-image {
            max-width: 300px;
            max-height: 300px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        #thoughtsContent, #answerContent {
            max-height: 500px;
            overflow-y: auto;
        }
    </style>
</head>
<body class="p-4 md:p-8">
    <div class="container mx-auto max-w-4xl">
        <div class="glass-card rounded-3xl p-8 md:p-12">
            <div class="text-center mb-12">
                <h1 class="text-5xl font-bold text-white glow mb-4">Mariam M-0</h1>
                <p class="text-blue-200 text-lg">Solution Mathématique Intelligente</p>
            </div>

            <form id="problemForm" class="space-y-8" enctype="multipart/form-data">
                <div class="relative">
                    <div class="uploadArea rounded-2xl p-12 text-center transition-all duration-300 cursor-pointer">
                        <input type="file" id="imageInput" name="image" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer">
                        <div class="space-y-4">
                            <div class="w-20 h-20 mx-auto border-2 border-blue-400 rounded-full flex items-center justify-center">
                                <svg class="w-10 h-10 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
                                </svg>
                            </div>
                            <div class="text-blue-200 text-lg font-medium">Déposez votre image ici</div>
                            <div class="text-blue-300/60 text-sm">ou cliquez pour sélectionner</div>
                        </div>
                    </div>
                    <div id="imagePreview" class="preview-container hidden">
                        <img id="previewImage" src="#" alt="Prévisualisation de l'image" class="preview-image">
                    </div>
                </div>

                <button type="submit" class="neon-button w-full py-4 rounded-xl text-white font-medium text-lg transition-all duration-300">
                    Résoudre le problème
                </button>
            </form>

            <div id="loader" class="hidden mt-12">
                <div class="flex flex-col items-center justify-center space-y-4">
                    <span class="loader"></span>
                    <div class="text-blue-200 text-lg">Analyse en cours...</div>
                </div>
            </div>

            <div id="solution" class="hidden mt-12 space-y-8">
                <div class="glass-card rounded-2xl p-6">
                    <button id="thoughtsToggle" class="w-full flex justify-between items-center text-left text-lg font-medium text-white hover:text-blue-300 transition-colors">
                        <span>Processus de Réflexion</span>
                        <svg class="w-6 h-6 transform transition-transform duration-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                        </svg>
                    </button>
                    <div id="thoughtsBox" class="thought-box">
                        <div id="thoughtsContent" class="prose prose-invert max-w-none text-blue-100 mt-4"></div>
                    </div>
                </div>

                <div class="glass-card rounded-2xl p-8">
                    <h3 class="text-2xl font-bold text-white mb-6">Solution</h3>
                    <div id="answerContent" class="prose prose-invert max-w-none text-blue-100"></div>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const form = document.getElementById('problemForm');
            const imageInput = document.getElementById('imageInput');
            const loader = document.getElementById('loader');
            const solutionDiv = document.getElementById('solution');
            const thoughtsContent = document.getElementById('thoughtsContent');
            const answerContent = document.getElementById('answerContent');
            const thoughtsToggle = document.getElementById('thoughtsToggle');
            const thoughtsBox = document.getElementById('thoughtsBox');
            const imagePreview = document.getElementById('imagePreview');
            const previewImage = document.getElementById('previewImage');

            thoughtsToggle.addEventListener('click', () => {
                thoughtsBox.classList.toggle('open');
                thoughtsToggle.querySelector('svg').classList.toggle('rotate-180');
            });

            // Image preview handling
            imageInput.addEventListener('change', function(e) {
                const file = this.files[0];
                if (file) {
                    const reader = new FileReader();
                    reader.onload = function(e) {
                        previewImage.src = e.target.result;
                        imagePreview.classList.remove('hidden');
                    }
                    reader.readAsDataURL(file);
                } else {
                    previewImage.src = "";
                    imagePreview.classList.add('hidden');
                }
            });

            // Drag and drop handling
            const dropZone = document.querySelector('.uploadArea');

            ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
                dropZone.addEventListener(eventName, preventDefaults, false);
            });

            function preventDefaults(e) {
                e.preventDefault();
                e.stopPropagation();
            }

            ['dragenter', 'dragover'].forEach(eventName => {
                dropZone.addEventListener(eventName, highlight, false);
            });

            ['dragleave', 'drop'].forEach(eventName => {
                dropZone.addEventListener(eventName, unhighlight, false);
            });

            function highlight(e) {
                dropZone.classList.add('border-blue-400');
            }

            function unhighlight(e) {
                dropZone.classList.remove('border-blue-400');
            }

            dropZone.addEventListener('drop', handleDrop, false);

            function handleDrop(e) {
                const dt = e.dataTransfer;
                const files = dt.files;

                if (files.length) {
                    imageInput.files = files;
                    const file = files[0];
                    const reader = new FileReader();
                    reader.onload = function(e) {
                        previewImage.src = e.target.result;
                        imagePreview.classList.remove('hidden');
                    }
                    reader.readAsDataURL(file);
                }
            }

            // Form submission and streaming
            form.addEventListener('submit', async (event) => {
                event.preventDefault();
                const file = imageInput.files[0];
                if (!file) {
                    alert('Veuillez sélectionner une image.');
                    return;
                }

                // Reset UI
                loader.classList.remove('hidden');
                solutionDiv.classList.add('hidden');
                thoughtsContent.innerHTML = '';
                answerContent.innerHTML = '';
                thoughtsBox.classList.add('open');

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

                try {
                    let currentMode = null;
                    const response = await fetch('/solve', {
                        method: 'POST',
                        body: formData
                    });

                    const reader = response.body.getReader();
                    const decoder = new TextDecoder();
                    let buffer = '';

                    while (true) {
                        const { done, value } = await reader.read();
                        if (done) break;

                        buffer += decoder.decode(value, { stream: true });
                        let eolIndex;

                        while ((eolIndex = buffer.indexOf('\n\n')) >= 0) {
                            const line = buffer.slice(0, eolIndex).trim();
                            buffer = buffer.slice(eolIndex + 2);

                            if (line.startsWith('data:')) {
                                const data = JSON.parse(line.slice(5));
                                
                                if (data.mode) {
                                    currentMode = data.mode;
                                    loader.classList.add('hidden');
                                    solutionDiv.classList.remove('hidden');
                                }
                                
                                if (data.content) {
                                    const content = data.content;
                                    if (currentMode === 'thinking') {
                                        thoughtsContent.innerHTML += `<p>${content}</p>`;
                                        thoughtsContent.scrollTop = thoughtsContent.scrollHeight;
                                    } else if (currentMode === 'answering') {
                                        answerContent.innerHTML += content;
                                        if (window.MathJax) {
                                            MathJax.Hub.Queue(["Typeset", MathJax.Hub, answerContent]);
                                        }
                                    }
                                }
                            }
                        }
                    }

                } catch (error) {
                    console.error('Erreur:', error);
                    alert('Une erreur est survenue lors du traitement de la requête.');
                    loader.classList.add('hidden');
                }
            });
        });
    </script>
</body>
</html>