Spaces:
Running
Running
Commit ·
0333b18
1
Parent(s): 0ee86b0
Enhance UI and improve code readability across multiple HTML files; update database.py and api.py for better functionality and error handling.
Browse files- infrastructure/database.py +2 -2
- routes/api.py +3 -1
- static/chunks.html +25 -3
- static/dbviewer.html +20 -4
- static/manifest.html +19 -3
- static/upload.html +4 -2
infrastructure/database.py
CHANGED
|
@@ -18,7 +18,7 @@ TOK_VER = int(os.getenv("TOK_VER", "1"))
|
|
| 18 |
SEG_VER = int(os.getenv("SEG_VER", "1"))
|
| 19 |
|
| 20 |
# ---------------------------------------------------------------------------
|
| 21 |
-
# ChromaDB
|
| 22 |
# ---------------------------------------------------------------------------
|
| 23 |
# Set a writable cache directory for ChromaDB with fallbacks
|
| 24 |
def _setup_cache_dir():
|
|
@@ -642,7 +642,7 @@ def get_embedding_counts_for_chunks(chunk_ids: List[int]) -> dict[int, int]:
|
|
| 642 |
embedding_counts[chunk_id] = 0
|
| 643 |
|
| 644 |
# Check which chunks have embeddings
|
| 645 |
-
if chunk_data['ids'] and chunk_data['embeddings']:
|
| 646 |
for i, chunk_id_str in enumerate(chunk_data['ids']):
|
| 647 |
chunk_id = int(chunk_id_str)
|
| 648 |
embedding = chunk_data['embeddings'][i]
|
|
|
|
| 18 |
SEG_VER = int(os.getenv("SEG_VER", "1"))
|
| 19 |
|
| 20 |
# ---------------------------------------------------------------------------
|
| 21 |
+
# ChromaDB setup (with HuggingFace / read-only filesystem resilience)
|
| 22 |
# ---------------------------------------------------------------------------
|
| 23 |
# Set a writable cache directory for ChromaDB with fallbacks
|
| 24 |
def _setup_cache_dir():
|
|
|
|
| 642 |
embedding_counts[chunk_id] = 0
|
| 643 |
|
| 644 |
# Check which chunks have embeddings
|
| 645 |
+
if chunk_data['ids'] and chunk_data['embeddings'] is not None:
|
| 646 |
for i, chunk_id_str in enumerate(chunk_data['ids']):
|
| 647 |
chunk_id = int(chunk_id_str)
|
| 648 |
embedding = chunk_data['embeddings'][i]
|
routes/api.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# api.py
|
| 2 |
import os
|
| 3 |
from flask import Blueprint, request, jsonify, send_from_directory
|
|
|
|
| 4 |
from werkzeug.utils import secure_filename
|
| 5 |
from infrastructure.logger import get_logger
|
| 6 |
|
|
@@ -30,6 +31,7 @@ from infrastructure.chunker import chunk_doc
|
|
| 30 |
from infrastructure.vector_search import find_nearest_neighbors
|
| 31 |
|
| 32 |
api_bp = Blueprint("api", __name__, url_prefix="/api")
|
|
|
|
| 33 |
logger = get_logger()
|
| 34 |
RESET_PASSWORD = os.getenv("RESET_PASSWORD")
|
| 35 |
|
|
@@ -106,7 +108,7 @@ def add_doc():
|
|
| 106 |
|
| 107 |
doc = update_document(doc_id=doc_id_val, updates={"source_path": raw_path})
|
| 108 |
|
| 109 |
-
|
| 110 |
sha256=content_sha,
|
| 111 |
title=title,
|
| 112 |
source_path=raw_path,
|
|
|
|
| 1 |
# api.py
|
| 2 |
import os
|
| 3 |
from flask import Blueprint, request, jsonify, send_from_directory
|
| 4 |
+
from flask_cors import CORS
|
| 5 |
from werkzeug.utils import secure_filename
|
| 6 |
from infrastructure.logger import get_logger
|
| 7 |
|
|
|
|
| 31 |
from infrastructure.vector_search import find_nearest_neighbors
|
| 32 |
|
| 33 |
api_bp = Blueprint("api", __name__, url_prefix="/api")
|
| 34 |
+
CORS(api_bp)
|
| 35 |
logger = get_logger()
|
| 36 |
RESET_PASSWORD = os.getenv("RESET_PASSWORD")
|
| 37 |
|
|
|
|
| 108 |
|
| 109 |
doc = update_document(doc_id=doc_id_val, updates={"source_path": raw_path})
|
| 110 |
|
| 111 |
+
upsert_manifest_record(
|
| 112 |
sha256=content_sha,
|
| 113 |
title=title,
|
| 114 |
source_path=raw_path,
|
static/chunks.html
CHANGED
|
@@ -9,7 +9,23 @@
|
|
| 9 |
body{font-family:-apple-system,BlinkMacSystemFont,'SF Pro Rounded','SF Pro Display',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;background:#001122;color:#fff;min-height:100vh;padding:28px;display:flex;flex-direction:column;align-items:center;gap:28px}
|
| 10 |
.shell{width:100%;max-width:1400px;display:flex;flex-direction:column;gap:26px}
|
| 11 |
.panel{background:#333;border-radius:20px;padding:26px 32px;box-shadow:0 18px 50px rgba(0,0,0,.5);display:flex;flex-direction:column;gap:20px}
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
p.sub{font-size:.8rem;color:#ccc;font-style:italic;line-height:1.5;margin:0}
|
| 14 |
a{color:#87CEFA;text-decoration:none}a:hover{text-decoration:underline}
|
| 15 |
form.query{display:flex;flex-wrap:wrap;gap:14px;align-items:flex-end}
|
|
@@ -60,8 +76,8 @@
|
|
| 60 |
<body>
|
| 61 |
<div class="shell">
|
| 62 |
<div class="panel">
|
| 63 |
-
<h1>Chunks Explorer</h1>
|
| 64 |
-
<p class="
|
| 65 |
<form id="queryForm" class="query" autocomplete="off">
|
| 66 |
<div>
|
| 67 |
<label for="docId">Document ID</label>
|
|
@@ -101,6 +117,12 @@
|
|
| 101 |
</div>
|
| 102 |
</div>
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
<script>
|
| 105 |
const form = document.getElementById('queryForm');
|
| 106 |
const docIdInput = document.getElementById('docId');
|
|
|
|
| 9 |
body{font-family:-apple-system,BlinkMacSystemFont,'SF Pro Rounded','SF Pro Display',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;background:#001122;color:#fff;min-height:100vh;padding:28px;display:flex;flex-direction:column;align-items:center;gap:28px}
|
| 10 |
.shell{width:100%;max-width:1400px;display:flex;flex-direction:column;gap:26px}
|
| 11 |
.panel{background:#333;border-radius:20px;padding:26px 32px;box-shadow:0 18px 50px rgba(0,0,0,.5);display:flex;flex-direction:column;gap:20px}
|
| 12 |
+
.header-title {
|
| 13 |
+
color: #fff;
|
| 14 |
+
font-size: 2.5rem;
|
| 15 |
+
font-weight: 500;
|
| 16 |
+
text-decoration: underline;
|
| 17 |
+
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
|
| 18 |
+
text-align: center;
|
| 19 |
+
margin: 10px;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.header-subtitle {
|
| 23 |
+
color: #ccc;
|
| 24 |
+
font-size: 0.85rem;
|
| 25 |
+
font-weight: 400;
|
| 26 |
+
font-style: italic;
|
| 27 |
+
margin: 5px;
|
| 28 |
+
}
|
| 29 |
p.sub{font-size:.8rem;color:#ccc;font-style:italic;line-height:1.5;margin:0}
|
| 30 |
a{color:#87CEFA;text-decoration:none}a:hover{text-decoration:underline}
|
| 31 |
form.query{display:flex;flex-wrap:wrap;gap:14px;align-items:flex-end}
|
|
|
|
| 76 |
<body>
|
| 77 |
<div class="shell">
|
| 78 |
<div class="panel">
|
| 79 |
+
<h1 class="header-title">Chunks Explorer</h1>
|
| 80 |
+
<p class="header-subtitle">Paginated table view of chunks data with inline editing capabilities. Chunks are embedded in the RAG model using ChromaDB.</p>
|
| 81 |
<form id="queryForm" class="query" autocomplete="off">
|
| 82 |
<div>
|
| 83 |
<label for="docId">Document ID</label>
|
|
|
|
| 117 |
</div>
|
| 118 |
</div>
|
| 119 |
|
| 120 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 121 |
+
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
|
| 122 |
+
← Back to Home
|
| 123 |
+
</a>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
<script>
|
| 127 |
const form = document.getElementById('queryForm');
|
| 128 |
const docIdInput = document.getElementById('docId');
|
static/dbviewer.html
CHANGED
|
@@ -12,7 +12,23 @@
|
|
| 12 |
}
|
| 13 |
.shell { width:100%; max-width:1200px; display:flex; flex-direction:column; gap:26px; }
|
| 14 |
.panel { background:#333; border-radius:20px; padding:28px 32px; box-shadow:0 18px 50px rgba(0,0,0,.5); }
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
p.sub { font-size:.8rem; color:#ccc; font-style:italic; line-height:1.5; }
|
| 17 |
a { color:#87CEFA; text-decoration:none; }
|
| 18 |
a:hover { text-decoration:underline; }
|
|
@@ -59,9 +75,9 @@
|
|
| 59 |
<body>
|
| 60 |
<div class="shell">
|
| 61 |
<div class="panel">
|
| 62 |
-
<h1>Database Viewer</h1>
|
| 63 |
-
<p class="
|
| 64 |
-
|
| 65 |
<div class="view-toggles">
|
| 66 |
<button id="documentsTab" class="active" data-tab="documents">Documents</button>
|
| 67 |
<button id="chunksTab" data-tab="chunks">Chunks</button>
|
|
|
|
| 12 |
}
|
| 13 |
.shell { width:100%; max-width:1200px; display:flex; flex-direction:column; gap:26px; }
|
| 14 |
.panel { background:#333; border-radius:20px; padding:28px 32px; box-shadow:0 18px 50px rgba(0,0,0,.5); }
|
| 15 |
+
.header-title {
|
| 16 |
+
color: #fff;
|
| 17 |
+
font-size: 2.5rem;
|
| 18 |
+
font-weight: 500;
|
| 19 |
+
text-decoration: underline;
|
| 20 |
+
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
|
| 21 |
+
text-align: center;
|
| 22 |
+
margin: 10px;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.header-subtitle {
|
| 26 |
+
color: #ccc;
|
| 27 |
+
font-size: 0.85rem;
|
| 28 |
+
font-weight: 400;
|
| 29 |
+
font-style: italic;
|
| 30 |
+
margin: 5px;
|
| 31 |
+
}
|
| 32 |
p.sub { font-size:.8rem; color:#ccc; font-style:italic; line-height:1.5; }
|
| 33 |
a { color:#87CEFA; text-decoration:none; }
|
| 34 |
a:hover { text-decoration:underline; }
|
|
|
|
| 75 |
<body>
|
| 76 |
<div class="shell">
|
| 77 |
<div class="panel">
|
| 78 |
+
<h1 class="header-title">Database Viewer</h1>
|
| 79 |
+
<p class="header-subtitle">Browse documents and chunks stored in the ChromaDB database. Values are truncated - click to view the complete content.</p>
|
| 80 |
+
|
| 81 |
<div class="view-toggles">
|
| 82 |
<button id="documentsTab" class="active" data-tab="documents">Documents</button>
|
| 83 |
<button id="chunksTab" data-tab="chunks">Chunks</button>
|
static/manifest.html
CHANGED
|
@@ -12,7 +12,23 @@
|
|
| 12 |
}
|
| 13 |
.shell { width:100%; max-width:1200px; display:flex; flex-direction:column; gap:26px; }
|
| 14 |
.panel { background:#333; border-radius:20px; padding:28px 32px; box-shadow:0 18px 50px rgba(0,0,0,.5); }
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
p.sub { font-size:.8rem; color:#ccc; font-style:italic; line-height:1.5; }
|
| 17 |
a { color:#87CEFA; text-decoration:none; }
|
| 18 |
a:hover { text-decoration:underline; }
|
|
@@ -78,8 +94,8 @@
|
|
| 78 |
<body>
|
| 79 |
<div class="shell">
|
| 80 |
<div class="panel">
|
| 81 |
-
<h1>Global Manifest</h1>
|
| 82 |
-
<p class="
|
| 83 |
<form id="filterForm" class="query" autocomplete="off" style="margin-bottom:10px;">
|
| 84 |
<div>
|
| 85 |
<label for="filter">Text Filter</label>
|
|
|
|
| 12 |
}
|
| 13 |
.shell { width:100%; max-width:1200px; display:flex; flex-direction:column; gap:26px; }
|
| 14 |
.panel { background:#333; border-radius:20px; padding:28px 32px; box-shadow:0 18px 50px rgba(0,0,0,.5); }
|
| 15 |
+
.header-title {
|
| 16 |
+
color: #fff;
|
| 17 |
+
font-size: 2.5rem;
|
| 18 |
+
font-weight: 500;
|
| 19 |
+
text-decoration: underline;
|
| 20 |
+
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
|
| 21 |
+
text-align: center;
|
| 22 |
+
margin: 10px;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.header-subtitle {
|
| 26 |
+
color: #ccc;
|
| 27 |
+
font-size: 0.85rem;
|
| 28 |
+
font-weight: 400;
|
| 29 |
+
font-style: italic;
|
| 30 |
+
margin: 5px;
|
| 31 |
+
}
|
| 32 |
p.sub { font-size:.8rem; color:#ccc; font-style:italic; line-height:1.5; }
|
| 33 |
a { color:#87CEFA; text-decoration:none; }
|
| 34 |
a:hover { text-decoration:underline; }
|
|
|
|
| 94 |
<body>
|
| 95 |
<div class="shell">
|
| 96 |
<div class="panel">
|
| 97 |
+
<h1 class="header-title">Global Manifest</h1>
|
| 98 |
+
<p class="header-subtitle">Viewing stored documents manifest, available at <code>/data/manifest/manifest.jsonl</code>. Columns represent extracted / enriched metadata for all documents.</p><br />
|
| 99 |
<form id="filterForm" class="query" autocomplete="off" style="margin-bottom:10px;">
|
| 100 |
<div>
|
| 101 |
<label for="filter">Text Filter</label>
|
static/upload.html
CHANGED
|
@@ -178,8 +178,9 @@
|
|
| 178 |
cursor: pointer;
|
| 179 |
transition: all 0.3s ease;
|
| 180 |
letter-spacing: 1px;
|
| 181 |
-
margin
|
| 182 |
display: none;
|
|
|
|
| 183 |
}
|
| 184 |
|
| 185 |
.upload-button.visible {
|
|
@@ -315,7 +316,8 @@
|
|
| 315 |
|
| 316 |
<div class="upload-result" id="uploadResult"></div>
|
| 317 |
</div>
|
| 318 |
-
|
|
|
|
| 319 |
<div style="text-align: center; margin-top: 20px;">
|
| 320 |
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
|
| 321 |
← Back to Home
|
|
|
|
| 178 |
cursor: pointer;
|
| 179 |
transition: all 0.3s ease;
|
| 180 |
letter-spacing: 1px;
|
| 181 |
+
margin: 10px auto 0;
|
| 182 |
display: none;
|
| 183 |
+
align-self: center;
|
| 184 |
}
|
| 185 |
|
| 186 |
.upload-button.visible {
|
|
|
|
| 316 |
|
| 317 |
<div class="upload-result" id="uploadResult"></div>
|
| 318 |
</div>
|
| 319 |
+
<br />
|
| 320 |
+
<br />
|
| 321 |
<div style="text-align: center; margin-top: 20px;">
|
| 322 |
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
|
| 323 |
← Back to Home
|