Spaces:
Running
Running
it is not answering questions from the document
Browse filesI want answer that are fetched from the document
Got this : I received your question about "what is a deductible?". This would connect to a backend that processes the document
Want this :• A deductible is the amount of money you have to pay toward covered services each year before insurance will help pay. This amount is determined by your insurance plan and resets each year.
- README.md +8 -5
- components/footer.js +49 -0
- components/navbar.js +56 -0
- index.html +156 -19
- script.js +96 -0
- style.css +19 -19
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: DocuChat Oracle 🔮
|
| 3 |
+
colorFrom: yellow
|
| 4 |
+
colorTo: yellow
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
components/footer.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomFooter extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
footer {
|
| 7 |
+
background: #1F2937;
|
| 8 |
+
color: white;
|
| 9 |
+
padding: 2rem;
|
| 10 |
+
text-align: center;
|
| 11 |
+
margin-top: auto;
|
| 12 |
+
}
|
| 13 |
+
.container {
|
| 14 |
+
max-width: 1200px;
|
| 15 |
+
margin: 0 auto;
|
| 16 |
+
}
|
| 17 |
+
.links {
|
| 18 |
+
display: flex;
|
| 19 |
+
justify-content: center;
|
| 20 |
+
gap: 2rem;
|
| 21 |
+
margin-bottom: 1rem;
|
| 22 |
+
}
|
| 23 |
+
.links a {
|
| 24 |
+
color: #D1D5DB;
|
| 25 |
+
text-decoration: none;
|
| 26 |
+
transition: color 0.2s;
|
| 27 |
+
}
|
| 28 |
+
.links a:hover {
|
| 29 |
+
color: white;
|
| 30 |
+
}
|
| 31 |
+
.copyright {
|
| 32 |
+
color: #9CA3AF;
|
| 33 |
+
font-size: 0.875rem;
|
| 34 |
+
}
|
| 35 |
+
</style>
|
| 36 |
+
<footer>
|
| 37 |
+
<div class="container">
|
| 38 |
+
<div class="links">
|
| 39 |
+
<a href="#">Privacy</a>
|
| 40 |
+
<a href="#">Terms</a>
|
| 41 |
+
<a href="#">Contact</a>
|
| 42 |
+
</div>
|
| 43 |
+
<p class="copyright">© 2023 DocuChat Buddy. All rights reserved.</p>
|
| 44 |
+
</div>
|
| 45 |
+
</footer>
|
| 46 |
+
`;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
customElements.define('custom-footer', CustomFooter);
|
components/navbar.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomNavbar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
nav {
|
| 7 |
+
background: white;
|
| 8 |
+
padding: 1rem 2rem;
|
| 9 |
+
display: flex;
|
| 10 |
+
justify-content: space-between;
|
| 11 |
+
align-items: center;
|
| 12 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 13 |
+
}
|
| 14 |
+
.logo {
|
| 15 |
+
color: #6366F1;
|
| 16 |
+
font-weight: bold;
|
| 17 |
+
font-size: 1.25rem;
|
| 18 |
+
display: flex;
|
| 19 |
+
align-items: center;
|
| 20 |
+
gap: 0.5rem;
|
| 21 |
+
}
|
| 22 |
+
.logo-icon {
|
| 23 |
+
color: #10B981;
|
| 24 |
+
}
|
| 25 |
+
ul {
|
| 26 |
+
display: flex;
|
| 27 |
+
gap: 1.5rem;
|
| 28 |
+
list-style: none;
|
| 29 |
+
margin: 0;
|
| 30 |
+
padding: 0;
|
| 31 |
+
}
|
| 32 |
+
a {
|
| 33 |
+
color: #4B5563;
|
| 34 |
+
text-decoration: none;
|
| 35 |
+
transition: color 0.2s;
|
| 36 |
+
font-weight: 500;
|
| 37 |
+
}
|
| 38 |
+
a:hover {
|
| 39 |
+
color: #6366F1;
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
+
<nav>
|
| 43 |
+
<a href="/" class="logo">
|
| 44 |
+
<i data-feather="message-square" class="logo-icon"></i>
|
| 45 |
+
<span>DocuChat Buddy</span>
|
| 46 |
+
</a>
|
| 47 |
+
<ul>
|
| 48 |
+
<li><a href="/">Home</a></li>
|
| 49 |
+
<li><a href="#">API Docs</a></li>
|
| 50 |
+
<li><a href="#">About</a></li>
|
| 51 |
+
</ul>
|
| 52 |
+
</nav>
|
| 53 |
+
`;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
customElements.define('custom-navbar', CustomNavbar);
|
index.html
CHANGED
|
@@ -1,19 +1,156 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>DocuChat Buddy</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
<script>
|
| 12 |
+
tailwind.config = {
|
| 13 |
+
theme: {
|
| 14 |
+
extend: {
|
| 15 |
+
colors: {
|
| 16 |
+
primary: {
|
| 17 |
+
500: '#6366F1',
|
| 18 |
+
},
|
| 19 |
+
secondary: {
|
| 20 |
+
500: '#10B981',
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
</script>
|
| 27 |
+
</head>
|
| 28 |
+
<body class="bg-gray-50 min-h-screen flex flex-col">
|
| 29 |
+
<custom-navbar></custom-navbar>
|
| 30 |
+
|
| 31 |
+
<main class="flex-1 container mx-auto px-4 py-8">
|
| 32 |
+
<div class="max-w-3xl mx-auto bg-white rounded-xl shadow-md overflow-hidden">
|
| 33 |
+
<div class="p-6">
|
| 34 |
+
<h1 class="text-2xl font-bold text-gray-800 mb-6">DocuChat Buddy</h1>
|
| 35 |
+
|
| 36 |
+
<div class="border border-gray-200 rounded-lg p-4 h-96 overflow-y-auto mb-4" id="chat-container">
|
| 37 |
+
<div class="flex items-start mb-4">
|
| 38 |
+
<div class="bg-primary-500 text-white p-3 rounded-full mr-3">
|
| 39 |
+
<i data-feather="message-square" class="w-4 h-4"></i>
|
| 40 |
+
</div>
|
| 41 |
+
<div class="bg-gray-100 p-3 rounded-lg max-w-xs">
|
| 42 |
+
<p class="text-gray-700">Hello! Upload a document and I'll answer your questions about it.</p>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
|
| 47 |
+
<div class="flex items-center gap-2 mb-4">
|
| 48 |
+
<label for="file-upload" class="cursor-pointer bg-secondary-500 text-white px-4 py-2 rounded-lg hover:bg-secondary-600 transition flex items-center gap-2">
|
| 49 |
+
<i data-feather="upload" class="w-4 h-4"></i>
|
| 50 |
+
<span>Upload Document</span>
|
| 51 |
+
<input id="file-upload" type="file" class="hidden" accept=".pdf,.doc,.docx,.txt">
|
| 52 |
+
</label>
|
| 53 |
+
<span id="file-name" class="text-gray-500 text-sm truncate max-w-xs"></span>
|
| 54 |
+
</div>
|
| 55 |
+
|
| 56 |
+
<div class="flex gap-2">
|
| 57 |
+
<input type="text" id="user-input" placeholder="Ask something about the document..." class="flex-1 border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500">
|
| 58 |
+
<button id="send-btn" class="bg-primary-500 text-white px-4 py-2 rounded-lg hover:bg-primary-600 transition flex items-center gap-2">
|
| 59 |
+
<i data-feather="send" class="w-4 h-4"></i>
|
| 60 |
+
<span>Send</span>
|
| 61 |
+
</button>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
</main>
|
| 66 |
+
|
| 67 |
+
<custom-footer></custom-footer>
|
| 68 |
+
|
| 69 |
+
<script src="components/navbar.js"></script>
|
| 70 |
+
<script src="components/footer.js"></script>
|
| 71 |
+
<script src="script.js"></script>
|
| 72 |
+
<script>
|
| 73 |
+
feather.replace();
|
| 74 |
+
|
| 75 |
+
// Simple chat functionality
|
| 76 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 77 |
+
const chatContainer = document.getElementById('chat-container');
|
| 78 |
+
const userInput = document.getElementById('user-input');
|
| 79 |
+
const sendBtn = document.getElementById('send-btn');
|
| 80 |
+
const fileUpload = document.getElementById('file-upload');
|
| 81 |
+
const fileName = document.getElementById('file-name');
|
| 82 |
+
|
| 83 |
+
fileUpload.addEventListener('change', function(e) {
|
| 84 |
+
if (e.target.files.length > 0) {
|
| 85 |
+
fileName.textContent = e.target.files[0].name;
|
| 86 |
+
await processDocument(e.target.files[0]);
|
| 87 |
+
addMessage('bot', 'Document uploaded! You can now ask questions about it.');
|
| 88 |
+
}
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
sendBtn.addEventListener('click', sendMessage);
|
| 92 |
+
userInput.addEventListener('keypress', function(e) {
|
| 93 |
+
if (e.key === 'Enter') sendMessage();
|
| 94 |
+
});
|
| 95 |
+
|
| 96 |
+
function sendMessage() {
|
| 97 |
+
const message = userInput.value.trim();
|
| 98 |
+
if (message) {
|
| 99 |
+
addMessage('user', message);
|
| 100 |
+
userInput.value = '';
|
| 101 |
+
// Get answer from document
|
| 102 |
+
setTimeout(async () => {
|
| 103 |
+
try {
|
| 104 |
+
const response = await askQuestion(message);
|
| 105 |
+
if (response.answer.includes("couldn't find")) {
|
| 106 |
+
addMessage('bot', response.answer);
|
| 107 |
+
} else {
|
| 108 |
+
// Format the answer better
|
| 109 |
+
const formattedAnswer = "• " + response.answer.replace(/\n/g, '\n• ');
|
| 110 |
+
addMessage('bot', formattedAnswer);
|
| 111 |
+
}
|
| 112 |
+
} catch (error) {
|
| 113 |
+
addMessage('bot', "Sorry, I encountered an error processing your question.");
|
| 114 |
+
console.error(error);
|
| 115 |
+
}
|
| 116 |
+
}, 800);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function addMessage(sender, text) {
|
| 121 |
+
const messageDiv = document.createElement('div');
|
| 122 |
+
messageDiv.className = `flex items-start mb-4 ${sender === 'user' ? 'justify-end' : ''}`;
|
| 123 |
+
|
| 124 |
+
const messageContent = document.createElement('div');
|
| 125 |
+
messageContent.className = sender === 'user'
|
| 126 |
+
? 'bg-primary-500 text-white p-3 rounded-lg max-w-xs'
|
| 127 |
+
: 'bg-gray-100 p-3 rounded-lg max-w-xs';
|
| 128 |
+
messageContent.textContent = text;
|
| 129 |
+
|
| 130 |
+
const iconDiv = document.createElement('div');
|
| 131 |
+
iconDiv.className = sender === 'user'
|
| 132 |
+
? 'bg-primary-500 text-white p-3 rounded-full ml-3'
|
| 133 |
+
: 'bg-primary-500 text-white p-3 rounded-full mr-3';
|
| 134 |
+
|
| 135 |
+
const icon = document.createElement('i');
|
| 136 |
+
icon.setAttribute('data-feather', sender === 'user' ? 'user' : 'message-square');
|
| 137 |
+
icon.className = 'w-4 h-4';
|
| 138 |
+
iconDiv.appendChild(icon);
|
| 139 |
+
|
| 140 |
+
if (sender === 'user') {
|
| 141 |
+
messageDiv.appendChild(messageContent);
|
| 142 |
+
messageDiv.appendChild(iconDiv);
|
| 143 |
+
} else {
|
| 144 |
+
messageDiv.appendChild(iconDiv);
|
| 145 |
+
messageDiv.appendChild(messageContent);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
chatContainer.appendChild(messageDiv);
|
| 149 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 150 |
+
feather.replace();
|
| 151 |
+
}
|
| 152 |
+
});
|
| 153 |
+
</script>
|
| 154 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 155 |
+
</body>
|
| 156 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// Document content storage
|
| 3 |
+
let documentContent = '';
|
| 4 |
+
|
| 5 |
+
// Process uploaded document
|
| 6 |
+
async function processDocument(file) {
|
| 7 |
+
return new Promise((resolve) => {
|
| 8 |
+
const reader = new FileReader();
|
| 9 |
+
reader.onload = (e) => {
|
| 10 |
+
documentContent = e.target.result;
|
| 11 |
+
resolve({ success: true });
|
| 12 |
+
};
|
| 13 |
+
reader.readAsText(file);
|
| 14 |
+
});
|
| 15 |
+
}
|
| 16 |
+
// Enhanced document search function with semantic matching
|
| 17 |
+
function searchDocument(question) {
|
| 18 |
+
if (!documentContent) return "Please upload a document first.";
|
| 19 |
+
|
| 20 |
+
const questionLower = question.toLowerCase();
|
| 21 |
+
const docLower = documentContent.toLowerCase();
|
| 22 |
+
|
| 23 |
+
// Split into paragraphs first for better context
|
| 24 |
+
const paragraphs = documentContent.split('\n\n');
|
| 25 |
+
|
| 26 |
+
// Search for direct matches first
|
| 27 |
+
for (const paragraph of paragraphs) {
|
| 28 |
+
const paraLower = paragraph.toLowerCase();
|
| 29 |
+
|
| 30 |
+
if (paraLower.includes(questionLower) ||
|
| 31 |
+
(questionLower.includes('what') && paraLower.includes('is') && paraLower.includes(questionLower.split('what is ')[1]))) {
|
| 32 |
+
// Clean up the paragraph and return the most relevant sentence
|
| 33 |
+
const sentences = paragraph.split(/[.!?]+/);
|
| 34 |
+
for (const sentence of sentences) {
|
| 35 |
+
if (sentence.toLowerCase().includes(questionLower)) {
|
| 36 |
+
return sentence.trim() + '.';
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
return paragraph.trim();
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// If no direct match, try to find related content
|
| 44 |
+
const keywords = questionLower.split(' ');
|
| 45 |
+
let bestMatch = '';
|
| 46 |
+
let highestScore = 0;
|
| 47 |
+
|
| 48 |
+
for (const paragraph of paragraphs) {
|
| 49 |
+
const paraLower = paragraph.toLowerCase();
|
| 50 |
+
let score = 0;
|
| 51 |
+
|
| 52 |
+
for (const word of keywords) {
|
| 53 |
+
if (word.length > 3 && paraLower.includes(word)) {
|
| 54 |
+
score++;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
if (score > highestScore) {
|
| 59 |
+
highestScore = score;
|
| 60 |
+
bestMatch = paragraph;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
if (bestMatch) {
|
| 65 |
+
// Extract the most relevant sentence
|
| 66 |
+
const sentences = bestMatch.split(/[.!?]+/);
|
| 67 |
+
for (const sentence of sentences) {
|
| 68 |
+
if (sentence.toLowerCase().includes(keywords[0])) {
|
| 69 |
+
return sentence.trim() + '.';
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
return bestMatch.trim();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
return "I couldn't find a specific answer in the document. Please try rephrasing your question.";
|
| 76 |
+
}
|
| 77 |
+
async function askQuestion(question) {
|
| 78 |
+
if (!documentContent) {
|
| 79 |
+
return { answer: "Please upload a document first." };
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
const answer = searchDocument(question);
|
| 83 |
+
|
| 84 |
+
// Enhance simple answers with more context
|
| 85 |
+
let enhancedAnswer = answer;
|
| 86 |
+
if (answer.includes('is') && !answer.includes('.')) {
|
| 87 |
+
// Try to find the next sentence for more context
|
| 88 |
+
const sentences = documentContent.split(/[.!?]+/);
|
| 89 |
+
const idx = sentences.findIndex(s => s.trim() + '.' === answer);
|
| 90 |
+
if (idx !== -1 && idx < sentences.length - 1) {
|
| 91 |
+
enhancedAnswer += ' ' + sentences[idx+1].trim() + '.';
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return { answer: enhancedAnswer };
|
| 96 |
+
}
|
style.css
CHANGED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
margin: 0 auto;
|
| 21 |
-
padding: 16px;
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Custom scrollbar for chat container */
|
| 2 |
+
#chat-container::-webkit-scrollbar {
|
| 3 |
+
width: 6px;
|
| 4 |
}
|
| 5 |
|
| 6 |
+
#chat-container::-webkit-scrollbar-track {
|
| 7 |
+
background: #f1f1f1;
|
| 8 |
+
border-radius: 10px;
|
| 9 |
}
|
| 10 |
|
| 11 |
+
#chat-container::-webkit-scrollbar-thumb {
|
| 12 |
+
background: #ccc;
|
| 13 |
+
border-radius: 10px;
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
+
#chat-container::-webkit-scrollbar-thumb:hover {
|
| 17 |
+
background: #aaa;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
+
/* Animation for messages */
|
| 21 |
+
@keyframes fadeIn {
|
| 22 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 23 |
+
to { opacity: 1; transform: translateY(0); }
|
| 24 |
}
|
| 25 |
+
|
| 26 |
+
#chat-container > div {
|
| 27 |
+
animation: fadeIn 0.3s ease-out;
|
| 28 |
+
}
|