Spaces:
Sleeping
Sleeping
Create index.html
Browse files- templates/index.html +70 -0
templates/index.html
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
</head>
|
| 9 |
+
<body class="bg-gray-100 p-8">
|
| 10 |
+
<div class="container mx-auto max-w-2xl bg-white p-8 rounded-lg shadow-md">
|
| 11 |
+
<h1 class="text-3xl font-bold mb-6 text-center">Math Problem Solver</h1>
|
| 12 |
+
|
| 13 |
+
<form id="problemForm" class="space-y-4">
|
| 14 |
+
<input type="file" id="imageInput" accept="image/*" class="w-full p-2 border border-gray-300 rounded-md">
|
| 15 |
+
<button type="submit" class="w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-700">Solve</button>
|
| 16 |
+
</form>
|
| 17 |
+
|
| 18 |
+
<div id="solution" class="mt-6 hidden">
|
| 19 |
+
<h2 class="text-2xl font-semibold mb-4">Solution</h2>
|
| 20 |
+
<div id="thoughts" class="p-4 border border-gray-300 rounded-md mb-4">
|
| 21 |
+
<h3 class="font-bold mb-2">Thoughts:</h3>
|
| 22 |
+
<pre id="thoughtsContent" class="whitespace-pre-wrap"></pre>
|
| 23 |
+
</div>
|
| 24 |
+
<div id="answer" class="p-4 border border-gray-300 rounded-md">
|
| 25 |
+
<h3 class="font-bold mb-2">Answer:</h3>
|
| 26 |
+
<pre id="answerContent" class="whitespace-pre-wrap"></pre>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
+
|
| 31 |
+
<script>
|
| 32 |
+
const form = document.getElementById('problemForm');
|
| 33 |
+
const imageInput = document.getElementById('imageInput');
|
| 34 |
+
const solutionDiv = document.getElementById('solution');
|
| 35 |
+
const thoughtsContent = document.getElementById('thoughtsContent');
|
| 36 |
+
const answerContent = document.getElementById('answerContent');
|
| 37 |
+
|
| 38 |
+
form.addEventListener('submit', async (event) => {
|
| 39 |
+
event.preventDefault();
|
| 40 |
+
const file = imageInput.files[0];
|
| 41 |
+
if (!file) {
|
| 42 |
+
alert('Please select an image file.');
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const formData = new FormData();
|
| 47 |
+
formData.append('image', file);
|
| 48 |
+
|
| 49 |
+
try {
|
| 50 |
+
const response = await fetch('/solve', {
|
| 51 |
+
method: 'POST',
|
| 52 |
+
body: formData,
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
const data = await response.json();
|
| 56 |
+
if (response.ok) {
|
| 57 |
+
thoughtsContent.textContent = data.thoughts;
|
| 58 |
+
answerContent.textContent = data.answer;
|
| 59 |
+
solutionDiv.classList.remove('hidden');
|
| 60 |
+
} else {
|
| 61 |
+
alert('Error: ' + data.error);
|
| 62 |
+
}
|
| 63 |
+
} catch (error) {
|
| 64 |
+
console.error('Error:', error);
|
| 65 |
+
alert('An error occurred while processing the request.');
|
| 66 |
+
}
|
| 67 |
+
});
|
| 68 |
+
</script>
|
| 69 |
+
</body>
|
| 70 |
+
</html>
|