gemma-3-chat-api / index.html
NanobotzAI's picture
Create index.html
6e314c7 verified
raw
history blame
2.01 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF-Based Chatbot</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; text-align: center; }
#chat-container { max-width: 600px; margin: auto; }
input, button { padding: 10px; margin: 10px; }
#response { margin-top: 20px; white-space: pre-wrap; }
</style>
</head>
<body>
<h2>Chat with Your PDF</h2>
<!-- PDF Upload -->
<input type="file" id="pdfInput">
<button onclick="uploadPDF()">Upload PDF</button>
<hr>
<!-- Chat Section -->
<div id="chat-container">
<input type="text" id="userMessage" placeholder="Ask a question">
<button onclick="sendMessage()">Send</button>
<p id="response"></p>
</div>
<script>
function uploadPDF() {
let fileInput = document.getElementById('pdfInput');
if (!fileInput.files.length) {
alert("Please select a PDF file.");
return;
}
let filePath = fileInput.files[0].name;
fetch(`/upload_pdf/?file_path=${filePath}`, { method: "POST" })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error("Error uploading PDF:", error));
}
function sendMessage() {
let userMessage = document.getElementById('userMessage').value;
if (!userMessage.trim()) {
alert("Please enter a message.");
return;
}
fetch(`/chat/?msg=${encodeURIComponent(userMessage)}`)
.then(response => response.json())
.then(data => document.getElementById('response').innerText = "AI: " + data.response)
.catch(error => console.error("Error fetching response:", error));
}
</script>
</body>
</html>