Mariam-cards / templates /index.html
Docfile's picture
Create index.html
236c7d2 verified
raw
history blame
2.84 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math Problem Solver</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 p-8">
<div class="container mx-auto max-w-2xl bg-white p-8 rounded-lg shadow-md">
<h1 class="text-3xl font-bold mb-6 text-center">Math Problem Solver</h1>
<form id="problemForm" class="space-y-4">
<input type="file" id="imageInput" accept="image/*" class="w-full p-2 border border-gray-300 rounded-md">
<button type="submit" class="w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-700">Solve</button>
</form>
<div id="solution" class="mt-6 hidden">
<h2 class="text-2xl font-semibold mb-4">Solution</h2>
<div id="thoughts" class="p-4 border border-gray-300 rounded-md mb-4">
<h3 class="font-bold mb-2">Thoughts:</h3>
<pre id="thoughtsContent" class="whitespace-pre-wrap"></pre>
</div>
<div id="answer" class="p-4 border border-gray-300 rounded-md">
<h3 class="font-bold mb-2">Answer:</h3>
<pre id="answerContent" class="whitespace-pre-wrap"></pre>
</div>
</div>
</div>
<script>
const form = document.getElementById('problemForm');
const imageInput = document.getElementById('imageInput');
const solutionDiv = document.getElementById('solution');
const thoughtsContent = document.getElementById('thoughtsContent');
const answerContent = document.getElementById('answerContent');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const file = imageInput.files[0];
if (!file) {
alert('Please select an image file.');
return;
}
const formData = new FormData();
formData.append('image', file);
try {
const response = await fetch('/solve', {
method: 'POST',
body: formData,
});
const data = await response.json();
if (response.ok) {
thoughtsContent.textContent = data.thoughts;
answerContent.textContent = data.answer;
solutionDiv.classList.remove('hidden');
} else {
alert('Error: ' + data.error);
}
} catch (error) {
console.error('Error:', error);
alert('An error occurred while processing the request.');
}
});
</script>
</body>
</html>