Spaces:
Paused
Paused
Update templates/index.html
Browse files- templates/index.html +80 -20
templates/index.html
CHANGED
|
@@ -5,46 +5,37 @@
|
|
| 5 |
<title>Bible Search App</title>
|
| 6 |
<style>
|
| 7 |
body { font-family: sans-serif; margin: 2em; background-color: #f4f4f9; color: #333; }
|
| 8 |
-
h1, h2, h3 { color: #4a4a4a; }
|
| 9 |
.container { max-width: 800px; margin: auto; background: #fff; padding: 2em; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
input[type="text"] { width: 70%; padding: 0.8em; border: 1px solid #ccc; border-radius: 4px; }
|
| 11 |
input[type="submit"] { padding: 0.8em 1.5em; border: none; background-color: #5c67f2; color: white; border-radius: 4px; cursor: pointer; }
|
| 12 |
input[type="submit"]:hover { background-color: #4a54e1; }
|
| 13 |
.result { border: 1px solid #e1e1e8; padding: 1em; margin-bottom: 1em; border-radius: 5px; background: #fdfdff; }
|
| 14 |
.reference { font-weight: bold; color: #5c67f2; }
|
| 15 |
-
.flash { padding: 1em; margin-bottom: 1em; border-radius: 4px; }
|
| 16 |
-
.flash.warning { background-color: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
|
| 17 |
-
.flash.info { background-color: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
|
| 18 |
-
.flash.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
|
| 19 |
hr { border: none; border-top: 1px solid #e1e1e8; margin: 2em 0; }
|
| 20 |
-
.admin-section { background-color: #f8f9fa; padding: 1.5em; border-radius: 5px; border: 1px solid #e1e1e8; }
|
| 21 |
</style>
|
| 22 |
</head>
|
| 23 |
<body>
|
| 24 |
<div class="container">
|
| 25 |
-
<!-- Flash messages will appear here -->
|
| 26 |
-
{% with messages = get_flashed_messages(with_categories=true) %}
|
| 27 |
-
{% if messages %}
|
| 28 |
-
{% for category, message in messages %}
|
| 29 |
-
<div class="flash {{ category }}">{{ message }}</div>
|
| 30 |
-
{% endfor %}
|
| 31 |
-
{% endif %}
|
| 32 |
-
{% endwith %}
|
| 33 |
-
|
| 34 |
<h1>Bible Search</h1>
|
| 35 |
<form action="/search" method="post">
|
| 36 |
<input type="text" name="query" size="50" value="{{ query or '' }}" placeholder="e.g., love is patient, love is kind">
|
| 37 |
<input type="submit" value="Search">
|
| 38 |
</form>
|
| 39 |
-
|
| 40 |
<hr>
|
| 41 |
-
|
| 42 |
<div class="admin-section">
|
| 43 |
<h3>Admin Panel</h3>
|
| 44 |
-
<form
|
| 45 |
-
<p>
|
| 46 |
-
<input type="submit" value="Build and Push Database to Hub">
|
| 47 |
</form>
|
|
|
|
| 48 |
</div>
|
| 49 |
|
| 50 |
{% if query %}
|
|
@@ -61,5 +52,74 @@
|
|
| 61 |
{% endfor %}
|
| 62 |
{% endif %}
|
| 63 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
</body>
|
| 65 |
</html>
|
|
|
|
| 5 |
<title>Bible Search App</title>
|
| 6 |
<style>
|
| 7 |
body { font-family: sans-serif; margin: 2em; background-color: #f4f4f9; color: #333; }
|
|
|
|
| 8 |
.container { max-width: 800px; margin: auto; background: #fff; padding: 2em; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
| 9 |
+
.admin-section { background-color: #f8f9fa; padding: 1.5em; border-radius: 5px; border: 1px solid #e1e1e8; }
|
| 10 |
+
#build-status { margin-top: 1em; padding: 1em; border-radius: 4px; display: none; }
|
| 11 |
+
#build-status.info { background-color: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
|
| 12 |
+
#build-status.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
|
| 13 |
+
#build-status.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
|
| 14 |
+
/* Other styles remain the same */
|
| 15 |
+
h1, h2, h3 { color: #4a4a4a; }
|
| 16 |
input[type="text"] { width: 70%; padding: 0.8em; border: 1px solid #ccc; border-radius: 4px; }
|
| 17 |
input[type="submit"] { padding: 0.8em 1.5em; border: none; background-color: #5c67f2; color: white; border-radius: 4px; cursor: pointer; }
|
| 18 |
input[type="submit"]:hover { background-color: #4a54e1; }
|
| 19 |
.result { border: 1px solid #e1e1e8; padding: 1em; margin-bottom: 1em; border-radius: 5px; background: #fdfdff; }
|
| 20 |
.reference { font-weight: bold; color: #5c67f2; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
hr { border: none; border-top: 1px solid #e1e1e8; margin: 2em 0; }
|
|
|
|
| 22 |
</style>
|
| 23 |
</head>
|
| 24 |
<body>
|
| 25 |
<div class="container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
<h1>Bible Search</h1>
|
| 27 |
<form action="/search" method="post">
|
| 28 |
<input type="text" name="query" size="50" value="{{ query or '' }}" placeholder="e.g., love is patient, love is kind">
|
| 29 |
<input type="submit" value="Search">
|
| 30 |
</form>
|
|
|
|
| 31 |
<hr>
|
|
|
|
| 32 |
<div class="admin-section">
|
| 33 |
<h3>Admin Panel</h3>
|
| 34 |
+
<form id="build-form">
|
| 35 |
+
<p>Build the vector database from the JSON files and upload it for persistence. <strong>Requires a write-permission HF_TOKEN secret.</strong></p>
|
| 36 |
+
<input type="submit" id="build-button" value="Build and Push Database to Hub">
|
| 37 |
</form>
|
| 38 |
+
<div id="build-status"></div>
|
| 39 |
</div>
|
| 40 |
|
| 41 |
{% if query %}
|
|
|
|
| 52 |
{% endfor %}
|
| 53 |
{% endif %}
|
| 54 |
</div>
|
| 55 |
+
|
| 56 |
+
<script>
|
| 57 |
+
const buildForm = document.getElementById('build-form');
|
| 58 |
+
const buildButton = document.getElementById('build-button');
|
| 59 |
+
const statusDiv = document.getElementById('build-status');
|
| 60 |
+
let statusInterval;
|
| 61 |
+
|
| 62 |
+
function updateStatusDisplay(status, message) {
|
| 63 |
+
statusDiv.style.display = 'block';
|
| 64 |
+
statusDiv.textContent = message;
|
| 65 |
+
statusDiv.className = ''; // Reset classes
|
| 66 |
+
|
| 67 |
+
if (status.startsWith('IN_PROGRESS')) {
|
| 68 |
+
statusDiv.classList.add('info');
|
| 69 |
+
buildButton.disabled = true;
|
| 70 |
+
buildButton.value = 'Building...';
|
| 71 |
+
} else if (status === 'SUCCESS') {
|
| 72 |
+
statusDiv.classList.add('success');
|
| 73 |
+
buildButton.disabled = false;
|
| 74 |
+
buildButton.value = 'Build and Push Database to Hub';
|
| 75 |
+
clearInterval(statusInterval);
|
| 76 |
+
// Prompt user to refresh to load the new data
|
| 77 |
+
if(confirm("Build successful! Refresh the page to start searching?")) {
|
| 78 |
+
window.location.reload();
|
| 79 |
+
}
|
| 80 |
+
} else if (status === 'FAILED') {
|
| 81 |
+
statusDiv.classList.add('error');
|
| 82 |
+
buildButton.disabled = false;
|
| 83 |
+
buildButton.value = 'Try Build Again';
|
| 84 |
+
clearInterval(statusInterval);
|
| 85 |
+
} else { // NOT_STARTED
|
| 86 |
+
statusDiv.style.display = 'none';
|
| 87 |
+
buildButton.disabled = false;
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
async function checkStatus() {
|
| 92 |
+
try {
|
| 93 |
+
const response = await fetch('/status');
|
| 94 |
+
const data = await response.json();
|
| 95 |
+
updateStatusDisplay(data.status, data.message);
|
| 96 |
+
} catch (error) {
|
| 97 |
+
console.error('Error fetching status:', error);
|
| 98 |
+
updateStatusDisplay('FAILED', 'Could not connect to server to get status.');
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
buildForm.addEventListener('submit', async function(event) {
|
| 103 |
+
event.preventDefault();
|
| 104 |
+
|
| 105 |
+
if (!confirm('This will start the build process. It can take a long time. Are you sure?')) {
|
| 106 |
+
return;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
buildButton.disabled = true;
|
| 110 |
+
updateStatusDisplay('IN_PROGRESS', 'Initiating build process...');
|
| 111 |
+
|
| 112 |
+
try {
|
| 113 |
+
await fetch('/build-rag', { method: 'POST' });
|
| 114 |
+
// Start polling for status updates every 5 seconds
|
| 115 |
+
statusInterval = setInterval(checkStatus, 5000);
|
| 116 |
+
} catch (error) {
|
| 117 |
+
updateStatusDisplay('FAILED', 'Failed to send build request to the server.');
|
| 118 |
+
}
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
// Check status on page load
|
| 122 |
+
document.addEventListener('DOMContentLoaded', checkStatus);
|
| 123 |
+
</script>
|
| 124 |
</body>
|
| 125 |
</html>
|