Docfile commited on
Commit
1f7f905
·
verified ·
1 Parent(s): 61a8581

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +132 -71
templates/index.html CHANGED
@@ -1,98 +1,159 @@
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>Math Problem Solver</title>
7
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
8
- <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
9
- <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  </head>
11
- <body class="bg-gray-100 p-8 font-sans">
12
- <div class="container mx-auto max-w-4xl bg-white p-8 rounded-lg shadow-lg">
13
- <h1 class="text-4xl font-bold mb-6 text-center text-blue-700">Math Problem Solver</h1>
 
 
 
 
 
14
 
15
- <form id="problemForm" class="space-y-6">
16
- <div class="flex items-center justify-center w-full">
17
- <label for="imageInput" class="flex flex-col items-center justify-center w-full h-64 border-2 border-blue-300 border-dashed rounded-lg cursor-pointer bg-blue-50 hover:bg-blue-100 hover:border-blue-400">
18
- <div class="flex flex-col items-center justify-center pt-5 pb-6">
19
- <svg aria-hidden="true" class="w-10 h-10 mb-3 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"></path></svg>
20
- <p class="mb-2 text-sm text-blue-500"><span class="font-semibold">Click to upload</span> or drag and drop</p>
21
- <p class="text-xs text-blue-500">PNG, JPG, or JPEG</p>
 
 
 
 
 
22
  </div>
23
- <input id="imageInput" type="file" accept="image/*" class="hidden" />
24
- </label>
 
 
 
 
 
 
 
 
 
 
25
  </div>
26
- <button type="submit" class="w-full bg-blue-600 text-white font-bold py-3 px-6 rounded-lg hover:bg-blue-800 transition duration-300 ease-in-out">Solve</button>
27
- </form>
28
 
29
- <div id="loader" class="hidden flex justify-center mt-6">
30
- <div class="animate-spin rounded-full h-16 w-16 border-t-2 border-b-2 border-blue-500"></div>
31
- </div>
 
 
 
 
 
 
 
 
 
32
 
33
- <div id="solution" class="mt-8 hidden">
34
- <h2 class="text-2xl font-semibold mb-4 text-center">Solution</h2>
35
- <details class="mb-4 border border-gray-300 rounded-md">
36
- <summary class="p-4 cursor-pointer font-bold bg-gray-100 hover:bg-gray-200">Show/Hide Thoughts</summary>
37
- <div id="thoughts" class="p-4">
38
- <pre id="thoughtsContent" class="whitespace-pre-wrap font-mono"></pre>
39
  </div>
40
- </details>
41
- <div id="answer" class="p-4 border border-gray-300 rounded-md">
42
- <h3 class="font-bold mb-2">Answer:</h3>
43
- <pre id="answerContent" class="whitespace-pre-wrap font-mono"></pre>
44
  </div>
45
  </div>
46
  </div>
47
 
48
  <script>
49
- const form = document.getElementById('problemForm');
50
- const imageInput = document.getElementById('imageInput');
51
- const solutionDiv = document.getElementById('solution');
52
- const thoughtsContent = document.getElementById('thoughtsContent');
53
- const answerContent = document.getElementById('answerContent');
54
- const loader = document.getElementById('loader');
 
 
 
55
 
56
- form.addEventListener('submit', async (event) => {
57
- event.preventDefault();
58
- const file = imageInput.files[0];
59
- if (!file) {
60
- alert('Please select an image file.');
61
- return;
62
- }
63
 
64
- const formData = new FormData();
65
- formData.append('image', file);
 
 
 
 
 
66
 
67
- // Afficher le loader et cacher la solution précédente
68
- loader.classList.remove('hidden');
69
- solutionDiv.classList.add('hidden');
70
 
71
- try {
72
- const response = await fetch('/solve', {
73
- method: 'POST',
74
- body: formData,
75
- });
76
 
77
- const data = await response.json();
78
- if (response.ok) {
79
- thoughtsContent.textContent = data.thoughts;
80
- answerContent.textContent = data.answer;
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- // Recharger MathJax pour le nouveau contenu
83
- MathJax.typesetPromise();
 
 
 
 
 
 
 
 
 
84
 
85
- solutionDiv.classList.remove('hidden');
86
- } else {
87
- alert('Error: ' + data.error);
 
 
88
  }
89
- } catch (error) {
90
- console.error('Error:', error);
91
- alert('An error occurred while processing the request.');
92
- } finally {
93
- // Cacher le loader
94
- loader.classList.add('hidden');
95
- }
96
  });
97
  </script>
98
  </body>
 
1
+ <!DOCTYPE html>
2
+ <html lang="fr">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Mariam M-0 | Résolveur de Problèmes Mathématiques</title>
7
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_HTML"></script>
9
+ <style>
10
+ @keyframes pulse {
11
+ 0% { transform: scale(1); }
12
+ 50% { transform: scale(1.05); }
13
+ 100% { transform: scale(1); }
14
+ }
15
+ .loader {
16
+ border-top-color: #3B82F6;
17
+ animation: spinner 1s linear infinite;
18
+ }
19
+ @keyframes spinner {
20
+ 0% { transform: rotate(0deg); }
21
+ 100% { transform: rotate(360deg); }
22
+ }
23
+ .thought-box {
24
+ transition: max-height 0.3s ease-out;
25
+ max-height: 0;
26
+ overflow: hidden;
27
+ }
28
+ .thought-box.open {
29
+ max-height: 500px;
30
+ }
31
+ </style>
32
  </head>
33
+ <body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen p-8">
34
+ <div class="container mx-auto max-w-3xl">
35
+ <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
36
+ <div class="flex items-center justify-center mb-8">
37
+ <h1 class="text-4xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-indigo-600">
38
+ Mariam M-0
39
+ </h1>
40
+ </div>
41
 
42
+ <form id="problemForm" class="space-y-6">
43
+ <div class="relative">
44
+ <div class="border-2 border-dashed border-gray-300 rounded-xl p-8 text-center hover:border-blue-500 transition-colors">
45
+ <input type="file" id="imageInput" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer">
46
+ <div class="space-y-2">
47
+ <svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
48
+ <path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
49
+ </svg>
50
+ <div class="text-gray-600">
51
+ Glissez une image ou cliquez pour sélectionner
52
+ </div>
53
+ </div>
54
  </div>
55
+ </div>
56
+
57
+ <button type="submit" class="w-full bg-gradient-to-r from-blue-600 to-indigo-600 text-white py-3 px-6 rounded-xl font-medium hover:from-blue-700 hover:to-indigo-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transform transition-all hover:scale-105">
58
+ Résoudre
59
+ </button>
60
+ </form>
61
+
62
+ <div id="loader" class="hidden mt-8">
63
+ <div class="flex justify-center items-center">
64
+ <div class="loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12"></div>
65
+ </div>
66
+ <div class="text-center mt-4 text-gray-600">Analyse en cours...</div>
67
  </div>
 
 
68
 
69
+ <div id="solution" class="mt-8 hidden space-y-6">
70
+ <div class="bg-gray-50 rounded-xl p-4">
71
+ <button id="thoughtsToggle" class="w-full flex justify-between items-center text-left font-semibold text-gray-700 hover:text-blue-600">
72
+ <span>Processus de réflexion</span>
73
+ <svg class="w-5 h-5 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
74
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
75
+ </svg>
76
+ </button>
77
+ <div id="thoughtsBox" class="thought-box mt-4">
78
+ <div id="thoughtsContent" class="prose max-w-none"></div>
79
+ </div>
80
+ </div>
81
 
82
+ <div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl p-6">
83
+ <h3 class="font-bold text-xl mb-4 text-gray-800">Solution</h3>
84
+ <div id="answerContent" class="prose max-w-none"></div>
 
 
 
85
  </div>
 
 
 
 
86
  </div>
87
  </div>
88
  </div>
89
 
90
  <script>
91
+ document.addEventListener('DOMContentLoaded', () => {
92
+ const form = document.getElementById('problemForm');
93
+ const imageInput = document.getElementById('imageInput');
94
+ const loader = document.getElementById('loader');
95
+ const solution = document.getElementById('solution');
96
+ const thoughtsContent = document.getElementById('thoughtsContent');
97
+ const answerContent = document.getElementById('answerContent');
98
+ const thoughtsToggle = document.getElementById('thoughtsToggle');
99
+ const thoughtsBox = document.getElementById('thoughtsBox');
100
 
101
+ // Toggle thoughts
102
+ thoughtsToggle.addEventListener('click', () => {
103
+ thoughtsBox.classList.toggle('open');
104
+ thoughtsToggle.querySelector('svg').classList.toggle('rotate-180');
105
+ });
 
 
106
 
107
+ form.addEventListener('submit', async (event) => {
108
+ event.preventDefault();
109
+ const file = imageInput.files[0];
110
+ if (!file) {
111
+ alert('Veuillez sélectionner une image.');
112
+ return;
113
+ }
114
 
115
+ // Show loader
116
+ loader.classList.remove('hidden');
117
+ solution.classList.add('hidden');
118
 
119
+ const formData = new FormData();
120
+ formData.append('image', file);
 
 
 
121
 
122
+ try {
123
+ const response = await fetch('/solve', {
124
+ method: 'POST',
125
+ body: formData,
126
+ });
127
+ const data = await response.json();
128
+
129
+ if (response.ok) {
130
+ thoughtsContent.innerHTML = data.thoughts;
131
+ answerContent.innerHTML = data.answer;
132
+
133
+ // Refresh MathJax
134
+ if (window.MathJax) {
135
+ MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
136
+ }
137
 
138
+ loader.classList.add('hidden');
139
+ solution.classList.remove('hidden');
140
+ } else {
141
+ throw new Error(data.error || 'Une erreur est survenue');
142
+ }
143
+ } catch (error) {
144
+ console.error('Error:', error);
145
+ alert(error.message);
146
+ loader.classList.add('hidden');
147
+ }
148
+ });
149
 
150
+ // File input visualization
151
+ imageInput.addEventListener('change', function() {
152
+ const fileName = this.files[0]?.name;
153
+ if (fileName) {
154
+ this.parentElement.querySelector('.text-gray-600').textContent = fileName;
155
  }
156
+ });
 
 
 
 
 
 
157
  });
158
  </script>
159
  </body>