Update app.py
Browse files
app.py
CHANGED
|
@@ -55,13 +55,11 @@ def _show_password_gate():
|
|
| 55 |
st.caption("⚠ if you forget your password, your data cannot be recovered.")
|
| 56 |
col1, col2 = st.columns([3, 1])
|
| 57 |
with col1:
|
| 58 |
-
# FIX: read from session_state key directly so value persists on button-click rerun
|
| 59 |
st.text_input("password", type="password", placeholder="enter a password…",
|
| 60 |
label_visibility="collapsed", key="pw_input")
|
| 61 |
with col2:
|
| 62 |
enter = st.button("→ enter", type="primary", use_container_width=True)
|
| 63 |
if enter:
|
| 64 |
-
# FIX: read from st.session_state, not a local variable that may be stale
|
| 65 |
password = st.session_state.get("pw_input", "")
|
| 66 |
if not password:
|
| 67 |
st.warning("enter a password first")
|
|
@@ -223,13 +221,12 @@ def _render_map_html(nodes: list, edges: list) -> str:
|
|
| 223 |
edges_js.append(
|
| 224 |
f"{{id: {i}, from: '{src}', to: '{tgt}', "
|
| 225 |
f"label: '{rel}', "
|
| 226 |
-
# FIX: higher contrast label with background box, bigger font, color-coded
|
| 227 |
-
f"font: {{color: '{lcolor}', size:
|
| 228 |
f"strokeWidth: 3, strokeColor: '#0e0e10', background: '#111820'}}, "
|
| 229 |
f"color: {{color: '#2a2a3a', highlight: '{lcolor}', hover: '{lcolor}88'}}, "
|
| 230 |
f"arrows: {{to: {{enabled: true, scaleFactor: 0.6}}}}, "
|
| 231 |
-
|
| 232 |
-
f"width: 1.5, smooth: {{type: 'curvedCW', roundness: 0.2}}}}"
|
| 233 |
)
|
| 234 |
edges_data.append({
|
| 235 |
"source": e["source"], "target": e["target"],
|
|
@@ -319,10 +316,9 @@ var kindColors = {{
|
|
| 319 |
var nodes = new vis.DataSet([{nodes_js_str}]);
|
| 320 |
var edges = new vis.DataSet([{edges_js_str}]);
|
| 321 |
var container = document.getElementById('graph');
|
| 322 |
-
|
| 323 |
-
//
|
| 324 |
-
//
|
| 325 |
-
// they had no hierarchy relation, causing the flat single-direction mess.
|
| 326 |
var network = new vis.Network(container,
|
| 327 |
{{nodes: nodes, edges: edges}},
|
| 328 |
{{
|
|
@@ -334,16 +330,16 @@ var network = new vis.Network(container,
|
|
| 334 |
enabled: true,
|
| 335 |
solver: 'forceAtlas2Based',
|
| 336 |
forceAtlas2Based: {{
|
| 337 |
-
gravitationalConstant: -
|
| 338 |
-
centralGravity: 0.
|
| 339 |
-
springLength:
|
| 340 |
-
springConstant: 0.
|
| 341 |
-
damping: 0.
|
| 342 |
-
avoidOverlap: 0.
|
| 343 |
}},
|
| 344 |
stabilization: {{
|
| 345 |
enabled: true,
|
| 346 |
-
iterations:
|
| 347 |
updateInterval: 25,
|
| 348 |
fit: true
|
| 349 |
}}
|
|
@@ -356,10 +352,10 @@ var network = new vis.Network(container,
|
|
| 356 |
edges: {{ chosen: true }}
|
| 357 |
}}
|
| 358 |
);
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
network.on('click', function(params) {{
|
| 364 |
if (params.nodes.length > 0) {{
|
| 365 |
var nid = params.nodes[0];
|
|
@@ -368,6 +364,7 @@ network.on('click', function(params) {{
|
|
| 368 |
showPanel(n, nid);
|
| 369 |
}}
|
| 370 |
}});
|
|
|
|
| 371 |
function showPanel(n, nid) {{
|
| 372 |
var color = kindColors[n.kind] || '#888';
|
| 373 |
var callers = edgesData.filter(function(e) {{ return e.target === nid; }})
|
|
@@ -465,7 +462,6 @@ with st.sidebar:
|
|
| 465 |
document.addEventListener('keydown', function(e) {
|
| 466 |
if ((e.ctrlKey || e.metaKey) && e.key === 'u') {
|
| 467 |
e.preventDefault();
|
| 468 |
-
// Find and click the file uploader input
|
| 469 |
const fileInput = document.querySelector('input[type="file"]');
|
| 470 |
if (fileInput) {
|
| 471 |
fileInput.click();
|
|
@@ -483,10 +479,8 @@ with st.sidebar:
|
|
| 483 |
is_image = ext in ("png", "jpg", "jpeg", "webp")
|
| 484 |
if fname not in st.session_state.linked_files:
|
| 485 |
st.session_state.linked_files.append(fname)
|
| 486 |
-
changed = True
|
| 487 |
if is_image:
|
| 488 |
-
# FIX: was missing changed=True for images — they were added to
|
| 489 |
-
# linked_files and file_contents but _save() was never called
|
| 490 |
st.session_state.file_contents[fname] = (f.getvalue(), "image")
|
| 491 |
changed = True
|
| 492 |
else:
|
|
@@ -494,15 +488,17 @@ with st.sidebar:
|
|
| 494 |
text = f.getvalue().decode("utf-8")
|
| 495 |
language = detect_language(fname)
|
| 496 |
st.session_state.file_contents[fname] = (text, language)
|
| 497 |
-
# FIX: set changed=True BEFORE add_file so a RAG error
|
| 498 |
-
# doesn't prevent the file from being saved to session
|
| 499 |
changed = True
|
| 500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
except Exception as ex:
|
| 502 |
st.warning(f"could not read {fname}: {ex}")
|
| 503 |
if changed:
|
| 504 |
_save()
|
| 505 |
-
st.rerun()
|
| 506 |
|
| 507 |
for fname in list(st.session_state.linked_files):
|
| 508 |
col_f, col_x = st.columns([5, 1])
|
|
|
|
| 55 |
st.caption("⚠ if you forget your password, your data cannot be recovered.")
|
| 56 |
col1, col2 = st.columns([3, 1])
|
| 57 |
with col1:
|
|
|
|
| 58 |
st.text_input("password", type="password", placeholder="enter a password…",
|
| 59 |
label_visibility="collapsed", key="pw_input")
|
| 60 |
with col2:
|
| 61 |
enter = st.button("→ enter", type="primary", use_container_width=True)
|
| 62 |
if enter:
|
|
|
|
| 63 |
password = st.session_state.get("pw_input", "")
|
| 64 |
if not password:
|
| 65 |
st.warning("enter a password first")
|
|
|
|
| 221 |
edges_js.append(
|
| 222 |
f"{{id: {i}, from: '{src}', to: '{tgt}', "
|
| 223 |
f"label: '{rel}', "
|
| 224 |
+
# FIX: higher contrast label with background box, bigger font, color-coded, align top
|
| 225 |
+
f"font: {{color: '{lcolor}', size: 12, face: 'IBM Plex Mono', align: 'top', "
|
| 226 |
f"strokeWidth: 3, strokeColor: '#0e0e10', background: '#111820'}}, "
|
| 227 |
f"color: {{color: '#2a2a3a', highlight: '{lcolor}', hover: '{lcolor}88'}}, "
|
| 228 |
f"arrows: {{to: {{enabled: true, scaleFactor: 0.6}}}}, "
|
| 229 |
+
f"width: 1.5, smooth: {{type: 'curvedCW', roundness: 0.3}}}}"
|
|
|
|
| 230 |
)
|
| 231 |
edges_data.append({
|
| 232 |
"source": e["source"], "target": e["target"],
|
|
|
|
| 316 |
var nodes = new vis.DataSet([{nodes_js_str}]);
|
| 317 |
var edges = new vis.DataSet([{edges_js_str}]);
|
| 318 |
var container = document.getElementById('graph');
|
| 319 |
+
|
| 320 |
+
// ForceAtlas2Based with strong repulsion and clustering parameters
|
| 321 |
+
// No physics disable after stabilization — keep graph alive and explorable
|
|
|
|
| 322 |
var network = new vis.Network(container,
|
| 323 |
{{nodes: nodes, edges: edges}},
|
| 324 |
{{
|
|
|
|
| 330 |
enabled: true,
|
| 331 |
solver: 'forceAtlas2Based',
|
| 332 |
forceAtlas2Based: {{
|
| 333 |
+
gravitationalConstant: -120,
|
| 334 |
+
centralGravity: 0.02,
|
| 335 |
+
springLength: 100,
|
| 336 |
+
springConstant: 0.1,
|
| 337 |
+
damping: 0.4,
|
| 338 |
+
avoidOverlap: 0.9
|
| 339 |
}},
|
| 340 |
stabilization: {{
|
| 341 |
enabled: true,
|
| 342 |
+
iterations: 500,
|
| 343 |
updateInterval: 25,
|
| 344 |
fit: true
|
| 345 |
}}
|
|
|
|
| 352 |
edges: {{ chosen: true }}
|
| 353 |
}}
|
| 354 |
);
|
| 355 |
+
|
| 356 |
+
// Do NOT disable physics after stabilization — let the graph continue to settle
|
| 357 |
+
// (the physics remains enabled for organic exploration)
|
| 358 |
+
|
| 359 |
network.on('click', function(params) {{
|
| 360 |
if (params.nodes.length > 0) {{
|
| 361 |
var nid = params.nodes[0];
|
|
|
|
| 364 |
showPanel(n, nid);
|
| 365 |
}}
|
| 366 |
}});
|
| 367 |
+
|
| 368 |
function showPanel(n, nid) {{
|
| 369 |
var color = kindColors[n.kind] || '#888';
|
| 370 |
var callers = edgesData.filter(function(e) {{ return e.target === nid; }})
|
|
|
|
| 462 |
document.addEventListener('keydown', function(e) {
|
| 463 |
if ((e.ctrlKey || e.metaKey) && e.key === 'u') {
|
| 464 |
e.preventDefault();
|
|
|
|
| 465 |
const fileInput = document.querySelector('input[type="file"]');
|
| 466 |
if (fileInput) {
|
| 467 |
fileInput.click();
|
|
|
|
| 479 |
is_image = ext in ("png", "jpg", "jpeg", "webp")
|
| 480 |
if fname not in st.session_state.linked_files:
|
| 481 |
st.session_state.linked_files.append(fname)
|
| 482 |
+
changed = True
|
| 483 |
if is_image:
|
|
|
|
|
|
|
| 484 |
st.session_state.file_contents[fname] = (f.getvalue(), "image")
|
| 485 |
changed = True
|
| 486 |
else:
|
|
|
|
| 488 |
text = f.getvalue().decode("utf-8")
|
| 489 |
language = detect_language(fname)
|
| 490 |
st.session_state.file_contents[fname] = (text, language)
|
|
|
|
|
|
|
| 491 |
changed = True
|
| 492 |
+
# RAG indexing is best-effort, do not block session save
|
| 493 |
+
try:
|
| 494 |
+
add_file(SID, fname, text)
|
| 495 |
+
except Exception as rag_err:
|
| 496 |
+
st.warning(f"RAG indexing failed for {fname}: {rag_err}")
|
| 497 |
except Exception as ex:
|
| 498 |
st.warning(f"could not read {fname}: {ex}")
|
| 499 |
if changed:
|
| 500 |
_save()
|
| 501 |
+
st.rerun()
|
| 502 |
|
| 503 |
for fname in list(st.session_state.linked_files):
|
| 504 |
col_f, col_x = st.columns([5, 1])
|