Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
.vscode/settings.json
CHANGED
|
@@ -9,5 +9,6 @@
|
|
| 9 |
],
|
| 10 |
"terminal.integrated.env.windows": {
|
| 11 |
"PYTHONPATH": "${workspaceFolder}"
|
| 12 |
-
}
|
|
|
|
| 13 |
}
|
|
|
|
| 9 |
],
|
| 10 |
"terminal.integrated.env.windows": {
|
| 11 |
"PYTHONPATH": "${workspaceFolder}"
|
| 12 |
+
},
|
| 13 |
+
"git.ignoreLimitWarning": true
|
| 14 |
}
|
frontend/package-lock.json
CHANGED
|
@@ -1380,7 +1380,6 @@
|
|
| 1380 |
"version": "2.99.2",
|
| 1381 |
"resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.99.2.tgz",
|
| 1382 |
"integrity": "sha512-179rn5wq0wBAqqGwAwR7TUGg2NOaP+fkd5FCVbYJXby85fsRNPFoNJN8YRBepqX2tN7JJcnTjqaAMXuNjiyisA==",
|
| 1383 |
-
"license": "MIT",
|
| 1384 |
"dependencies": {
|
| 1385 |
"@supabase/auth-js": "2.99.2",
|
| 1386 |
"@supabase/functions-js": "2.99.2",
|
|
|
|
| 1380 |
"version": "2.99.2",
|
| 1381 |
"resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.99.2.tgz",
|
| 1382 |
"integrity": "sha512-179rn5wq0wBAqqGwAwR7TUGg2NOaP+fkd5FCVbYJXby85fsRNPFoNJN8YRBepqX2tN7JJcnTjqaAMXuNjiyisA==",
|
|
|
|
| 1383 |
"dependencies": {
|
| 1384 |
"@supabase/auth-js": "2.99.2",
|
| 1385 |
"@supabase/functions-js": "2.99.2",
|
frontend/src/App.jsx
CHANGED
|
@@ -14,6 +14,7 @@ export default function App() {
|
|
| 14 |
const [appState, setAppState] = useState('home');
|
| 15 |
const [userName, setUserName] = useState('');
|
| 16 |
const [authError, setAuthError] = useState('');
|
|
|
|
| 17 |
|
| 18 |
useEffect(() => {
|
| 19 |
console.log("Current App State:", appState);
|
|
@@ -92,11 +93,11 @@ export default function App() {
|
|
| 92 |
|
| 93 |
const toggleTheme = () => setIsDark(!isDark);
|
| 94 |
|
| 95 |
-
const handleUploadComplete = () => {
|
| 96 |
// UploadModal already completed the upload — just navigate to dashboard.
|
| 97 |
-
//
|
| 98 |
-
|
| 99 |
-
|
| 100 |
navigateTo('dboard');
|
| 101 |
};
|
| 102 |
|
|
@@ -107,6 +108,7 @@ export default function App() {
|
|
| 107 |
isDark={isDark}
|
| 108 |
toggleTheme={toggleTheme}
|
| 109 |
userName={userName}
|
|
|
|
| 110 |
onLogout={() => {
|
| 111 |
setUserName('');
|
| 112 |
navigateTo('home');
|
|
|
|
| 14 |
const [appState, setAppState] = useState('home');
|
| 15 |
const [userName, setUserName] = useState('');
|
| 16 |
const [authError, setAuthError] = useState('');
|
| 17 |
+
const [initialPolicyId, setInitialPolicyId] = useState(null);
|
| 18 |
|
| 19 |
useEffect(() => {
|
| 20 |
console.log("Current App State:", appState);
|
|
|
|
| 93 |
|
| 94 |
const toggleTheme = () => setIsDark(!isDark);
|
| 95 |
|
| 96 |
+
const handleUploadComplete = (policyId) => {
|
| 97 |
// UploadModal already completed the upload — just navigate to dashboard.
|
| 98 |
+
// We store the received policy_id so Dboard knows which policy to open automatically.
|
| 99 |
+
console.log("Upload finished! Routing to Dboard with policy:", policyId);
|
| 100 |
+
setInitialPolicyId(policyId);
|
| 101 |
navigateTo('dboard');
|
| 102 |
};
|
| 103 |
|
|
|
|
| 108 |
isDark={isDark}
|
| 109 |
toggleTheme={toggleTheme}
|
| 110 |
userName={userName}
|
| 111 |
+
initialPolicyId={initialPolicyId}
|
| 112 |
onLogout={() => {
|
| 113 |
setUserName('');
|
| 114 |
navigateTo('home');
|
frontend/src/components/Dashboard/Dboard.jsx
CHANGED
|
@@ -211,6 +211,7 @@ export default function Dboard({ file, isDark: _initDark, userName = 'My Account
|
|
| 211 |
const handleMouseMove = (e) => {
|
| 212 |
if (!isResizingRef.current) return;
|
| 213 |
e.preventDefault();
|
|
|
|
| 214 |
|
| 215 |
const dir = isResizingRef.current;
|
| 216 |
setChatDimensions(prev => {
|
|
@@ -224,7 +225,10 @@ export default function Dboard({ file, isDark: _initDark, userName = 'My Account
|
|
| 224 |
});
|
| 225 |
};
|
| 226 |
const handleMouseUp = () => {
|
| 227 |
-
isResizingRef.current
|
|
|
|
|
|
|
|
|
|
| 228 |
};
|
| 229 |
window.addEventListener('mousemove', handleMouseMove);
|
| 230 |
window.addEventListener('mouseup', handleMouseUp);
|
|
|
|
| 211 |
const handleMouseMove = (e) => {
|
| 212 |
if (!isResizingRef.current) return;
|
| 213 |
e.preventDefault();
|
| 214 |
+
document.body.style.userSelect = 'none'; // Prevent text selection
|
| 215 |
|
| 216 |
const dir = isResizingRef.current;
|
| 217 |
setChatDimensions(prev => {
|
|
|
|
| 225 |
});
|
| 226 |
};
|
| 227 |
const handleMouseUp = () => {
|
| 228 |
+
if (isResizingRef.current) {
|
| 229 |
+
document.body.style.userSelect = '';
|
| 230 |
+
isResizingRef.current = null;
|
| 231 |
+
}
|
| 232 |
};
|
| 233 |
window.addEventListener('mousemove', handleMouseMove);
|
| 234 |
window.addEventListener('mouseup', handleMouseUp);
|
frontend/src/components/Dashboard/UploadModal.jsx
CHANGED
|
@@ -137,6 +137,7 @@ export default function UploadModal({ onUploadComplete, onCancel }) {
|
|
| 137 |
const [stage, setStage] = useState(-1);
|
| 138 |
const [dark, setDark] = useState(false);
|
| 139 |
const [backendMsg, setBackendMsg] = useState('');
|
|
|
|
| 140 |
|
| 141 |
const fileRef = useRef(null);
|
| 142 |
const dragCounter = useRef(0);
|
|
@@ -185,6 +186,7 @@ export default function UploadModal({ onUploadComplete, onCancel }) {
|
|
| 185 |
body: fd,
|
| 186 |
});
|
| 187 |
const pid = data.policy_id;
|
|
|
|
| 188 |
setPct(20);
|
| 189 |
|
| 190 |
// Poll for processing status every 2 s
|
|
@@ -230,11 +232,11 @@ export default function UploadModal({ onUploadComplete, onCancel }) {
|
|
| 230 |
completedRef.current = true;
|
| 231 |
const t1 = setTimeout(() => {
|
| 232 |
setStatus('done');
|
| 233 |
-
setTimeout(() => onCompleteRef.current(
|
| 234 |
}, 250);
|
| 235 |
return () => clearTimeout(t1);
|
| 236 |
}
|
| 237 |
-
}, [pct, status,
|
| 238 |
|
| 239 |
const validateAndPick = useCallback((f) => {
|
| 240 |
setError('');
|
|
|
|
| 137 |
const [stage, setStage] = useState(-1);
|
| 138 |
const [dark, setDark] = useState(false);
|
| 139 |
const [backendMsg, setBackendMsg] = useState('');
|
| 140 |
+
const [processedPid, setProcessedPid] = useState(null);
|
| 141 |
|
| 142 |
const fileRef = useRef(null);
|
| 143 |
const dragCounter = useRef(0);
|
|
|
|
| 186 |
body: fd,
|
| 187 |
});
|
| 188 |
const pid = data.policy_id;
|
| 189 |
+
setProcessedPid(pid);
|
| 190 |
setPct(20);
|
| 191 |
|
| 192 |
// Poll for processing status every 2 s
|
|
|
|
| 232 |
completedRef.current = true;
|
| 233 |
const t1 = setTimeout(() => {
|
| 234 |
setStatus('done');
|
| 235 |
+
setTimeout(() => onCompleteRef.current(processedPid), 800);
|
| 236 |
}, 250);
|
| 237 |
return () => clearTimeout(t1);
|
| 238 |
}
|
| 239 |
+
}, [pct, status, processedPid]); // ← onUploadComplete removed from deps
|
| 240 |
|
| 241 |
const validateAndPick = useCallback((f) => {
|
| 242 |
setError('');
|
rag_engine/embeddings/jina_embedder.py
CHANGED
|
@@ -40,13 +40,20 @@ class JinaEmbedder(BaseEmbedder):
|
|
| 40 |
return self._call_api([text])[0]
|
| 41 |
|
| 42 |
def embed_documents(self, texts: list[str]) -> list[list[float]]:
|
| 43 |
-
"""Process in batches of 100 (Jina API limit)."""
|
| 44 |
-
|
|
|
|
| 45 |
batch_size = 100
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
return all_embeddings
|
| 52 |
|
|
|
|
| 40 |
return self._call_api([text])[0]
|
| 41 |
|
| 42 |
def embed_documents(self, texts: list[str]) -> list[list[float]]:
|
| 43 |
+
"""Process in batches of 100 (Jina API limit) concurrently."""
|
| 44 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 45 |
+
|
| 46 |
batch_size = 100
|
| 47 |
+
batches = [texts[i : i + batch_size] for i in range(0, len(texts), batch_size)]
|
| 48 |
+
|
| 49 |
+
all_embeddings: list[list[float]] = []
|
| 50 |
+
|
| 51 |
+
with ThreadPoolExecutor(max_workers=5) as executor:
|
| 52 |
+
# map preserves order
|
| 53 |
+
results = list(executor.map(self._call_api, batches))
|
| 54 |
+
|
| 55 |
+
for r in results:
|
| 56 |
+
all_embeddings.extend(r)
|
| 57 |
|
| 58 |
return all_embeddings
|
| 59 |
|
rag_engine/vector_store/supabase_store.py
CHANGED
|
@@ -27,21 +27,28 @@ class SupabaseVectorStore(BaseVectorStore):
|
|
| 27 |
# ------------------------------------------------------------------ #
|
| 28 |
@with_retry(max_retries=3, delay=1.0, backoff=2.0)
|
| 29 |
def add_chunks(self, chunks: list[tuple[str, list[float], dict]]) -> None:
|
|
|
|
|
|
|
| 30 |
rows = [
|
| 31 |
{"content": text, "embedding": vector, "metadata": meta}
|
| 32 |
for text, vector, meta in chunks
|
| 33 |
]
|
| 34 |
total = (len(rows) + _BATCH_SIZE - 1) // _BATCH_SIZE
|
| 35 |
-
for i in range(0, len(rows), _BATCH_SIZE)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
try:
|
| 40 |
-
|
| 41 |
-
logger.info("Batch %d/%d stored successfully (%d rows)",
|
| 42 |
except Exception as e:
|
| 43 |
-
logger.error("FAILED to store batch %d/%d: %s",
|
| 44 |
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
logger.info("Successfully stored %d chunks in Supabase", len(chunks))
|
| 46 |
|
| 47 |
# ------------------------------------------------------------------ #
|
|
|
|
| 27 |
# ------------------------------------------------------------------ #
|
| 28 |
@with_retry(max_retries=3, delay=1.0, backoff=2.0)
|
| 29 |
def add_chunks(self, chunks: list[tuple[str, list[float], dict]]) -> None:
|
| 30 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 31 |
+
|
| 32 |
rows = [
|
| 33 |
{"content": text, "embedding": vector, "metadata": meta}
|
| 34 |
for text, vector, meta in chunks
|
| 35 |
]
|
| 36 |
total = (len(rows) + _BATCH_SIZE - 1) // _BATCH_SIZE
|
| 37 |
+
batches = [rows[i : i + _BATCH_SIZE] for i in range(0, len(rows), _BATCH_SIZE)]
|
| 38 |
+
|
| 39 |
+
def _insert_batch(batch_data: tuple[int, list[dict]]):
|
| 40 |
+
b_num, b_rows = batch_data
|
| 41 |
+
logger.info("Inserting batch %d/%d (%d rows) to Supabase...", b_num, total, len(b_rows))
|
| 42 |
try:
|
| 43 |
+
self._client.table(self._table).insert(b_rows).execute()
|
| 44 |
+
logger.info("Batch %d/%d stored successfully (%d rows)", b_num, total, len(b_rows))
|
| 45 |
except Exception as e:
|
| 46 |
+
logger.error("FAILED to store batch %d/%d: %s", b_num, total, str(e))
|
| 47 |
raise e
|
| 48 |
+
|
| 49 |
+
with ThreadPoolExecutor(max_workers=5) as executor:
|
| 50 |
+
list(executor.map(_insert_batch, [(i + 1, b) for i, b in enumerate(batches)]))
|
| 51 |
+
|
| 52 |
logger.info("Successfully stored %d chunks in Supabase", len(chunks))
|
| 53 |
|
| 54 |
# ------------------------------------------------------------------ #
|