@@ -1510,6 +1510,10 @@ def create_app(args):
|
||||
|
||||
return app
|
||||
|
||||
# Serve the static files
|
||||
static_dir = Path(__file__).parent / "static"
|
||||
static_dir.mkdir(exist_ok=True)
|
||||
app.mount("/", StaticFiles(directory=static_dir, html=True), name="static")
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
106
lightrag/api/static/index.html
Normal file
106
lightrag/api/static/index.html
Normal file
@@ -0,0 +1,106 @@
|
||||
<!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>
|
||||
|
||||
<!-- 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>
|
||||
// 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,
|
||||
});
|
||||
|
||||
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',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ query }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
queryResponse.textContent = `Response: ${data.result}`;
|
||||
} else {
|
||||
const error = await response.json();
|
||||
queryResponse.textContent = `Error: ${error.detail}`;
|
||||
}
|
||||
} catch (err) {
|
||||
queryResponse.textContent = `Error: ${err.message}`;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
1
lightrag/api/static/keep.txt
Normal file
1
lightrag/api/static/keep.txt
Normal file
@@ -0,0 +1 @@
|
||||
|
Reference in New Issue
Block a user