2025-01-24 13:52:26 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>RAG WebUI</title>
|
|
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
</head>
|
|
|
|
<body class="bg-gray-100 min-h-screen flex flex-col items-center justify-center p-4">
|
|
|
|
<div class="w-full max-w-4xl bg-white shadow-md rounded-lg p-6">
|
|
|
|
<h1 class="text-2xl font-bold text-gray-800 mb-4">RAG WebUI</h1>
|
|
|
|
|
2025-01-24 14:01:06 +01:00
|
|
|
<!-- Bearer Key Section -->
|
|
|
|
<div class="mb-6">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-2">Bearer Key</h2>
|
|
|
|
<div class="flex flex-col gap-4">
|
|
|
|
<input type="text" id="bearerKeyInput" class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter Bearer Key">
|
|
|
|
<button id="saveBearerKey" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Save Key</button>
|
|
|
|
<div id="bearerKeyStatus" class="text-sm text-gray-600"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2025-01-24 13:52:26 +01:00
|
|
|
<!-- File Upload Section -->
|
|
|
|
<div class="mb-6">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-2">Upload Files</h2>
|
|
|
|
<form id="uploadForm" class="flex flex-col gap-4">
|
|
|
|
<input type="file" id="fileInput" multiple class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
|
|
|
|
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Upload</button>
|
|
|
|
</form>
|
|
|
|
<div id="uploadStatus" class="mt-2 text-sm text-gray-600"></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Query Section -->
|
|
|
|
<div class="mb-6">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-2">Query</h2>
|
|
|
|
<form id="queryForm" class="flex flex-col gap-4">
|
|
|
|
<textarea id="queryInput" rows="4" class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter your query here..."></textarea>
|
|
|
|
<button type="submit" class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600">Submit Query</button>
|
|
|
|
</form>
|
|
|
|
<div id="queryResponse" class="mt-4 p-4 bg-gray-50 border rounded text-gray-700"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
2025-01-24 14:01:06 +01:00
|
|
|
// Bearer Key Handling
|
|
|
|
const bearerKeyInput = document.getElementById('bearerKeyInput');
|
|
|
|
const saveBearerKey = document.getElementById('saveBearerKey');
|
|
|
|
const bearerKeyStatus = document.getElementById('bearerKeyStatus');
|
|
|
|
|
|
|
|
// Load Bearer Key from localStorage on page load
|
|
|
|
const storedBearerKey = localStorage.getItem('bearerKey');
|
|
|
|
if (storedBearerKey) {
|
|
|
|
bearerKeyInput.value = storedBearerKey;
|
|
|
|
bearerKeyStatus.textContent = "Bearer Key loaded from local storage.";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save Bearer Key to localStorage
|
|
|
|
saveBearerKey.addEventListener('click', () => {
|
|
|
|
const key = bearerKeyInput.value.trim();
|
|
|
|
if (key) {
|
|
|
|
localStorage.setItem('bearerKey', key);
|
|
|
|
bearerKeyStatus.textContent = "Bearer Key saved successfully.";
|
|
|
|
} else {
|
|
|
|
bearerKeyStatus.textContent = "Please enter a valid Bearer Key.";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-01-24 13:52:26 +01:00
|
|
|
// File Upload Handler
|
|
|
|
const uploadForm = document.getElementById('uploadForm');
|
|
|
|
const fileInput = document.getElementById('fileInput');
|
|
|
|
const uploadStatus = document.getElementById('uploadStatus');
|
|
|
|
|
|
|
|
uploadForm.addEventListener('submit', async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const files = fileInput.files;
|
|
|
|
if (files.length === 0) {
|
|
|
|
uploadStatus.textContent = "Please select at least one file.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
for (const file of files) {
|
|
|
|
formData.append('file', file);
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadStatus.textContent = "Uploading...";
|
|
|
|
try {
|
|
|
|
const response = await fetch('/documents/upload', {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData,
|
2025-01-24 14:01:06 +01:00
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('bearerKey') || ''}`
|
|
|
|
}
|
2025-01-24 13:52:26 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
|
|
|
uploadStatus.textContent = `Upload successful! Indexed ${data.total_documents} documents.`;
|
|
|
|
} else {
|
|
|
|
const error = await response.json();
|
|
|
|
uploadStatus.textContent = `Error: ${error.detail}`;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
uploadStatus.textContent = `Error: ${err.message}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Query Handler
|
|
|
|
const queryForm = document.getElementById('queryForm');
|
|
|
|
const queryInput = document.getElementById('queryInput');
|
|
|
|
const queryResponse = document.getElementById('queryResponse');
|
|
|
|
|
|
|
|
queryForm.addEventListener('submit', async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const query = queryInput.value.trim();
|
|
|
|
if (!query) {
|
|
|
|
queryResponse.textContent = "Please enter a query.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
queryResponse.textContent = "Processing...";
|
|
|
|
try {
|
|
|
|
const response = await fetch('/query', {
|
|
|
|
method: 'POST',
|
2025-01-24 14:01:06 +01:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('bearerKey') || ''}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ query })
|
2025-01-24 13:52:26 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
2025-01-24 14:01:06 +01:00
|
|
|
queryResponse.textContent = `Response: ${data.response}`;
|
2025-01-24 13:52:26 +01:00
|
|
|
} else {
|
|
|
|
const error = await response.json();
|
|
|
|
queryResponse.textContent = `Error: ${error.detail}`;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
queryResponse.textContent = `Error: ${err.message}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|