peppinob-ol
commited on
Commit
·
e2019d7
1
Parent(s):
9b97db2
Fix: use graph data from session_state when file system is unavailable (HF Spaces compatibility)
Browse files- eda/pages/00_Graph_Generation.py +43 -19
eda/pages/00_Graph_Generation.py
CHANGED
|
@@ -443,26 +443,44 @@ if selected_json:
|
|
| 443 |
if not file_path.is_absolute():
|
| 444 |
file_path = parent_dir / selected_json
|
| 445 |
|
| 446 |
-
# Check if file exists
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
st.error(f"❌ File not found: `{file_path.name}`")
|
| 449 |
st.warning("The file may have been moved or renamed. Please refresh the page or select another file.")
|
| 450 |
st.stop()
|
| 451 |
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
# Display file info and graph metadata
|
| 468 |
col1, col2, col3 = st.columns(3)
|
|
@@ -487,9 +505,15 @@ if selected_json:
|
|
| 487 |
if st.button(button_label, key="extract_existing", type="primary"):
|
| 488 |
try:
|
| 489 |
with st.spinner("Extracting metrics..."):
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
graph_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
|
| 494 |
csv_output_path = str(parent_dir / "output" / "graph_feature_static_metrics.csv")
|
| 495 |
df = extract_static_metrics_from_json(
|
|
|
|
| 443 |
if not file_path.is_absolute():
|
| 444 |
file_path = parent_dir / selected_json
|
| 445 |
|
| 446 |
+
# Check if file exists - if not, try to use session_state data
|
| 447 |
+
file_exists = file_path.exists()
|
| 448 |
+
|
| 449 |
+
# If file doesn't exist but we have data in session_state (just generated), use that
|
| 450 |
+
use_session_data = False
|
| 451 |
+
if not file_exists and just_generated and 'pipeline_graph_json' in st.session_state:
|
| 452 |
+
graph_data = st.session_state['pipeline_graph_json']['data']
|
| 453 |
+
use_session_data = True
|
| 454 |
+
st.info("📦 Using graph data from current session (file system is temporary on HF Spaces)")
|
| 455 |
+
elif not file_exists:
|
| 456 |
st.error(f"❌ File not found: `{file_path.name}`")
|
| 457 |
st.warning("The file may have been moved or renamed. Please refresh the page or select another file.")
|
| 458 |
st.stop()
|
| 459 |
|
| 460 |
+
# Get file stats and metadata
|
| 461 |
+
if use_session_data:
|
| 462 |
+
# Use data from session_state
|
| 463 |
+
file_size = len(json.dumps(graph_data)) / 1024 / 1024 # Approximate size
|
| 464 |
+
file_time = datetime.fromisoformat(st.session_state['pipeline_graph_json']['timestamp'])
|
| 465 |
+
num_nodes = len(graph_data.get('nodes', []))
|
| 466 |
+
num_links = len(graph_data.get('links', []))
|
| 467 |
+
model_id = graph_data.get('metadata', {}).get('model_id', 'N/A')
|
| 468 |
+
else:
|
| 469 |
+
# Use file on disk
|
| 470 |
+
file_size = file_path.stat().st_size / 1024 / 1024
|
| 471 |
+
file_time = datetime.fromtimestamp(file_path.stat().st_mtime)
|
| 472 |
+
|
| 473 |
+
# Load JSON to extract graph metadata
|
| 474 |
+
try:
|
| 475 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 476 |
+
graph_metadata = json.load(f)
|
| 477 |
+
num_nodes = len(graph_metadata.get('nodes', []))
|
| 478 |
+
num_links = len(graph_metadata.get('links', []))
|
| 479 |
+
model_id = graph_metadata.get('metadata', {}).get('model_id', 'N/A')
|
| 480 |
+
except Exception:
|
| 481 |
+
num_nodes = None
|
| 482 |
+
num_links = None
|
| 483 |
+
model_id = None
|
| 484 |
|
| 485 |
# Display file info and graph metadata
|
| 486 |
col1, col2, col3 = st.columns(3)
|
|
|
|
| 505 |
if st.button(button_label, key="extract_existing", type="primary"):
|
| 506 |
try:
|
| 507 |
with st.spinner("Extracting metrics..."):
|
| 508 |
+
# Use graph_data from session_state if available, otherwise load from file
|
| 509 |
+
if use_session_data:
|
| 510 |
+
# Already have graph_data from session_state
|
| 511 |
+
pass
|
| 512 |
+
else:
|
| 513 |
+
# Load from file
|
| 514 |
+
json_full_path = str(parent_dir / selected_json)
|
| 515 |
+
with open(json_full_path, 'r', encoding='utf-8') as f:
|
| 516 |
+
graph_data = json.load(f)
|
| 517 |
|
| 518 |
csv_output_path = str(parent_dir / "output" / "graph_feature_static_metrics.csv")
|
| 519 |
df = extract_static_metrics_from_json(
|