Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +51 -17
templates/index.html
CHANGED
@@ -4,29 +4,63 @@
|
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>AI Question Answering</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
</head>
|
8 |
<body>
|
9 |
-
<h1>AI-
|
10 |
-
<h3>Ask questions about documents or images</h3>
|
11 |
|
12 |
-
<
|
13 |
-
|
14 |
-
<
|
15 |
-
|
16 |
-
<
|
17 |
-
<
|
18 |
-
|
19 |
-
<
|
|
|
20 |
</form>
|
|
|
21 |
|
22 |
-
<
|
23 |
-
<label for="question">Question (Image-based):</label>
|
24 |
-
<input type="text" id="question" name="question" required><br><br>
|
25 |
-
|
26 |
-
<label for="image_file">Upload Image:</label>
|
27 |
-
<input type="file" id="image_file" name="image_file" accept="image/*" required><br><br>
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
</form>
|
|
|
31 |
</body>
|
32 |
</html>
|
|
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>AI Question Answering</title>
|
7 |
+
<link rel="stylesheet" href="{{ url_for('static', path='/app.css') }}">
|
8 |
+
<script>
|
9 |
+
async function askQuestion(formId, resultId, endpoint) {
|
10 |
+
const form = document.getElementById(formId);
|
11 |
+
const formData = new FormData(form);
|
12 |
+
const resultDiv = document.getElementById(resultId);
|
13 |
+
|
14 |
+
resultDiv.innerHTML = "Processing...";
|
15 |
+
|
16 |
+
try {
|
17 |
+
const response = await fetch(endpoint, {
|
18 |
+
method: "POST",
|
19 |
+
body: formData
|
20 |
+
});
|
21 |
+
|
22 |
+
const data = await response.json();
|
23 |
+
if (data.error) {
|
24 |
+
resultDiv.innerHTML = "<b>Error:</b> " + data.error;
|
25 |
+
} else {
|
26 |
+
resultDiv.innerHTML = `<b>Answer:</b> ${data.answer}`;
|
27 |
+
if (data.image_text) {
|
28 |
+
resultDiv.innerHTML += `<br><b>Extracted Text:</b> ${data.image_text}`;
|
29 |
+
}
|
30 |
+
}
|
31 |
+
} catch (error) {
|
32 |
+
resultDiv.innerHTML = "<b>Error:</b> Failed to process.";
|
33 |
+
}
|
34 |
+
}
|
35 |
+
</script>
|
36 |
</head>
|
37 |
<body>
|
38 |
+
<h1>AI-Powered Question Answering</h1>
|
|
|
39 |
|
40 |
+
<h2>Ask a Question on a Document</h2>
|
41 |
+
<form id="docForm" onsubmit="event.preventDefault(); askQuestion('docForm', 'docResult', '/question-answering-doc');">
|
42 |
+
<label for="docQuestion">Enter your question:</label>
|
43 |
+
<input type="text" id="docQuestion" name="question" required>
|
44 |
+
<br><br>
|
45 |
+
<label for="docFile">Upload a document (PDF, DOCX, PPTX):</label>
|
46 |
+
<input type="file" id="docFile" name="file" accept=".pdf,.docx,.pptx" required>
|
47 |
+
<br><br>
|
48 |
+
<button type="submit">Ask</button>
|
49 |
</form>
|
50 |
+
<p id="docResult"></p>
|
51 |
|
52 |
+
<hr>
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
<h2>Ask a Question on an Image</h2>
|
55 |
+
<form id="imageForm" onsubmit="event.preventDefault(); askQuestion('imageForm', 'imageResult', '/question-answering-image');">
|
56 |
+
<label for="imageQuestion">Enter your question:</label>
|
57 |
+
<input type="text" id="imageQuestion" name="question" required>
|
58 |
+
<br><br>
|
59 |
+
<label for="imageFile">Upload an image:</label>
|
60 |
+
<input type="file" id="imageFile" name="image_file" accept="image/*" required>
|
61 |
+
<br><br>
|
62 |
+
<button type="submit">Ask</button>
|
63 |
</form>
|
64 |
+
<p id="imageResult"></p>
|
65 |
</body>
|
66 |
</html>
|