Spaces:
Paused
Paused
Update templates/index.html
Browse files- templates/index.html +115 -24
templates/index.html
CHANGED
|
@@ -1,38 +1,129 @@
|
|
| 1 |
-
<!-- templates/
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="en">
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
-
<title>
|
| 7 |
<style>
|
| 8 |
body { font-family: sans-serif; margin: 2em; background-color: #f4f4f9; color: #333; }
|
| 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 |
-
|
| 11 |
-
|
| 12 |
-
.
|
| 13 |
-
.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
</style>
|
| 18 |
</head>
|
| 19 |
<body>
|
| 20 |
<div class="container">
|
| 21 |
-
<
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
<hr>
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
<
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
</body>
|
| 38 |
-
</html>
|
|
|
|
| 1 |
+
<!-- templates/index.html -->
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="en">
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
+
<title>Bible Search App</title>
|
| 7 |
<style>
|
| 8 |
body { font-family: sans-serif; margin: 2em; background-color: #f4f4f9; color: #333; }
|
| 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 |
+
.admin-section { background-color: #f8f9fa; padding: 1.5em; border-radius: 5px; border: 1px solid #e1e1e8; }
|
| 11 |
+
#build-status { margin-top: 1em; padding: 1em; border-radius: 4px; display: none; }
|
| 12 |
+
#build-status.info { background-color: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
|
| 13 |
+
#build-status.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
|
| 14 |
+
#build-status.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
|
| 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; }
|
| 21 |
+
.reference a { color: #5c67f2; text-decoration: none; }
|
| 22 |
+
.reference a:hover { text-decoration: underline; }
|
| 23 |
+
hr { border: none; border-top: 1px solid #e1e1e8; margin: 2em 0; }
|
| 24 |
</style>
|
| 25 |
</head>
|
| 26 |
<body>
|
| 27 |
<div class="container">
|
| 28 |
+
<h1>Bible Search</h1>
|
| 29 |
+
<form action="/search" method="post">
|
| 30 |
+
<input type="text" name="query" size="50" value="{{ query or '' }}" placeholder="e.g., love is patient, love is kind">
|
| 31 |
+
<input type="submit" value="Search">
|
| 32 |
+
</form>
|
| 33 |
<hr>
|
| 34 |
+
<div class="admin-section">
|
| 35 |
+
<h3>Admin Panel</h3>
|
| 36 |
+
<form id="build-form">
|
| 37 |
+
<p>Build the vector database from the JSON files and upload it for persistence. <strong>Requires a write-permission HF_TOKEN secret.</strong></p>
|
| 38 |
+
<input type="submit" id="build-button" value="Build and Push Database to Hub">
|
| 39 |
+
</form>
|
| 40 |
+
<div id="build-status"></div>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
{% if query %}
|
| 44 |
+
<h2>Results for: "{{ query }}"</h2>
|
| 45 |
+
{% endif %}
|
| 46 |
+
|
| 47 |
+
{% if results %}
|
| 48 |
+
{% for result in results %}
|
| 49 |
+
<div class="result">
|
| 50 |
+
<!-- *** CHANGE 1: MAKE THE REFERENCE A CLICKABLE LINK *** -->
|
| 51 |
+
{% if result.book_name and result.chapter %}
|
| 52 |
+
<p class="reference">
|
| 53 |
+
<a href="{{ url_for('view_chapter', version=result.version, book_name=result.book_name, chapter_num=result.chapter) }}">
|
| 54 |
+
{{ result.reference }} ({{result.version}})
|
| 55 |
+
</a>
|
| 56 |
+
</p>
|
| 57 |
+
{% else %}
|
| 58 |
+
<p class="reference">{{ result.reference }} ({{result.version}})</p>
|
| 59 |
+
{% endif %}
|
| 60 |
+
<p>{{ result.text }}</p>
|
| 61 |
+
<small>Score (Distance): {{ "%.4f"|format(result.score) }}</small>
|
| 62 |
+
</div>
|
| 63 |
+
{% endfor %}
|
| 64 |
+
{% endif %}
|
| 65 |
</div>
|
| 66 |
+
|
| 67 |
+
<script>
|
| 68 |
+
const buildForm = document.getElementById('build-form');
|
| 69 |
+
const buildButton = document.getElementById('build-button');
|
| 70 |
+
const statusDiv = document.getElementById('build-status');
|
| 71 |
+
let statusInterval;
|
| 72 |
+
|
| 73 |
+
function updateStatusDisplay(status, message) {
|
| 74 |
+
statusDiv.style.display = 'block';
|
| 75 |
+
statusDiv.className = '';
|
| 76 |
+
|
| 77 |
+
if (status.startsWith('IN_PROGRESS')) {
|
| 78 |
+
statusDiv.classList.add('info');
|
| 79 |
+
buildButton.disabled = true;
|
| 80 |
+
buildButton.value = 'Building...';
|
| 81 |
+
statusDiv.textContent = message;
|
| 82 |
+
} else if (status === 'SUCCESS') {
|
| 83 |
+
statusDiv.classList.add('success');
|
| 84 |
+
buildButton.disabled = false;
|
| 85 |
+
buildButton.value = 'Build and Push Database to Hub';
|
| 86 |
+
clearInterval(statusInterval);
|
| 87 |
+
// *** CHANGE 2: REMOVE THE ANNOYING POPUP ***
|
| 88 |
+
// Simply update the text to inform the user.
|
| 89 |
+
statusDiv.textContent = message + " Refresh the page to use the new data.";
|
| 90 |
+
} else if (status === 'FAILED') {
|
| 91 |
+
statusDiv.classList.add('error');
|
| 92 |
+
buildButton.disabled = false;
|
| 93 |
+
buildButton.value = 'Try Build Again';
|
| 94 |
+
clearInterval(statusInterval);
|
| 95 |
+
statusDiv.textContent = message;
|
| 96 |
+
} else { // NOT_STARTED
|
| 97 |
+
statusDiv.style.display = 'none';
|
| 98 |
+
buildButton.disabled = false;
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
async function checkStatus() {
|
| 103 |
+
try {
|
| 104 |
+
const response = await fetch('/status');
|
| 105 |
+
const data = await response.json();
|
| 106 |
+
updateStatusDisplay(data.status, data.message);
|
| 107 |
+
} catch (error) {
|
| 108 |
+
console.error('Error fetching status:', error);
|
| 109 |
+
updateStatusDisplay('FAILED', 'Could not connect to server to get status.');
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
buildForm.addEventListener('submit', async function(event) {
|
| 114 |
+
event.preventDefault();
|
| 115 |
+
if (!confirm('This will rebuild the database, which can take a long time. Are you sure?')) return;
|
| 116 |
+
buildButton.disabled = true;
|
| 117 |
+
updateStatusDisplay('IN_PROGRESS', 'Initiating build process...');
|
| 118 |
+
try {
|
| 119 |
+
await fetch('/build-rag', { method: 'POST' });
|
| 120 |
+
statusInterval = setInterval(checkStatus, 5000);
|
| 121 |
+
} catch (error) {
|
| 122 |
+
updateStatusDisplay('FAILED', 'Failed to send build request to the server.');
|
| 123 |
+
}
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
document.addEventListener('DOMContentLoaded', checkStatus);
|
| 127 |
+
</script>
|
| 128 |
</body>
|
| 129 |
+
</html>
|