Claude commited on
Commit
eb2af28
·
1 Parent(s): 7831904

fix: Add robust error handling for all visualization builders

Browse files
Files changed (1) hide show
  1. app.py +55 -25
app.py CHANGED
@@ -937,30 +937,60 @@ def process_message(
937
  memory_browser_html = build_memory_browser_html(memory.get_state() if memory else None)
938
 
939
  # ===== BUILD VISUALIZATIONS =====
940
- spiderweb_fig = build_spiderweb_graph(
941
- state["spiderweb"].to_dict() if state.get("spiderweb") else None
942
- )
 
 
 
 
 
943
 
944
- coherence_fig = build_coherence_timeline(
945
- state.get("coherence_history", []),
946
- state.get("tension_history", [])
947
- )
 
 
 
 
 
948
 
949
- tension_fig = build_tension_heatmap(
950
- state["pairwise_tensions_history"][-1] if state.get("pairwise_tensions_history") else {}
951
- )
 
 
 
 
 
952
 
953
- aegis_fig = build_aegis_framework_gauges(
954
- state.get("aegis_framework_history", [])
955
- )
 
 
 
 
 
956
 
957
- memory_fig = build_memory_emotional_profile(
958
- memory.get_state() if memory else None
959
- )
 
 
 
 
 
960
 
961
- nexus_fig = build_nexus_risk_timeline(
962
- nexus.get_state() if nexus else None
963
- )
 
 
 
 
 
964
 
965
  return (
966
  chat_history,
@@ -972,12 +1002,12 @@ def process_message(
972
  memory_html,
973
  coverage_html,
974
  memory_browser_html,
975
- spiderweb_fig.to_html(include_plotlyjs='cdn') if isinstance(spiderweb_fig, go.Figure) else spiderweb_fig,
976
- coherence_fig.to_html(include_plotlyjs='cdn') if isinstance(coherence_fig, go.Figure) else coherence_fig,
977
- tension_fig.to_html(include_plotlyjs='cdn') if isinstance(tension_fig, go.Figure) else tension_fig,
978
- aegis_fig.to_html(include_plotlyjs='cdn') if isinstance(aegis_fig, go.Figure) else aegis_fig,
979
- memory_fig.to_html(include_plotlyjs='cdn') if isinstance(memory_fig, go.Figure) else memory_fig,
980
- nexus_fig.to_html(include_plotlyjs='cdn') if isinstance(nexus_fig, go.Figure) else nexus_fig,
981
  )
982
 
983
 
 
937
  memory_browser_html = build_memory_browser_html(memory.get_state() if memory else None)
938
 
939
  # ===== BUILD VISUALIZATIONS =====
940
+ try:
941
+ spiderweb_fig = build_spiderweb_graph(
942
+ state["spiderweb"].to_dict() if state.get("spiderweb") else None
943
+ )
944
+ spiderweb_html = spiderweb_fig.to_html(include_plotlyjs='cdn') if isinstance(spiderweb_fig, go.Figure) else str(spiderweb_fig)
945
+ except Exception as e:
946
+ print(f"Spiderweb viz error: {e}")
947
+ spiderweb_html = "<p>QuantumSpiderweb visualization unavailable</p>"
948
 
949
+ try:
950
+ coherence_fig = build_coherence_timeline(
951
+ state.get("coherence_history", []),
952
+ state.get("tension_history", [])
953
+ )
954
+ coherence_plot_html = coherence_fig.to_html(include_plotlyjs='cdn') if isinstance(coherence_fig, go.Figure) else str(coherence_fig)
955
+ except Exception as e:
956
+ print(f"Coherence viz error: {e}")
957
+ coherence_plot_html = "<p>Coherence timeline unavailable</p>"
958
 
959
+ try:
960
+ tension_fig = build_tension_heatmap(
961
+ state["pairwise_tensions_history"][-1] if state.get("pairwise_tensions_history") else {}
962
+ )
963
+ tension_plot_html = tension_fig.to_html(include_plotlyjs='cdn') if isinstance(tension_fig, go.Figure) else str(tension_fig)
964
+ except Exception as e:
965
+ print(f"Tension viz error: {e}")
966
+ tension_plot_html = "<p>Tension heatmap unavailable</p>"
967
 
968
+ try:
969
+ aegis_fig = build_aegis_framework_gauges(
970
+ state.get("aegis_framework_history", [])
971
+ )
972
+ aegis_plot_html = aegis_fig.to_html(include_plotlyjs='cdn') if isinstance(aegis_fig, go.Figure) else str(aegis_fig)
973
+ except Exception as e:
974
+ print(f"AEGIS viz error: {e}")
975
+ aegis_plot_html = "<p>AEGIS framework visualization unavailable</p>"
976
 
977
+ try:
978
+ memory_fig = build_memory_emotional_profile(
979
+ memory.get_state() if memory else None
980
+ )
981
+ memory_plot_html = memory_fig.to_html(include_plotlyjs='cdn') if isinstance(memory_fig, go.Figure) else str(memory_fig)
982
+ except Exception as e:
983
+ print(f"Memory viz error: {e}")
984
+ memory_plot_html = "<p>Memory visualization unavailable</p>"
985
 
986
+ try:
987
+ nexus_fig = build_nexus_risk_timeline(
988
+ nexus.get_state() if nexus else None
989
+ )
990
+ nexus_plot_html = nexus_fig.to_html(include_plotlyjs='cdn') if isinstance(nexus_fig, go.Figure) else str(nexus_fig)
991
+ except Exception as e:
992
+ print(f"Nexus viz error: {e}")
993
+ nexus_plot_html = "<p>Nexus timeline unavailable</p>"
994
 
995
  return (
996
  chat_history,
 
1002
  memory_html,
1003
  coverage_html,
1004
  memory_browser_html,
1005
+ spiderweb_html,
1006
+ coherence_plot_html,
1007
+ tension_plot_html,
1008
+ aegis_plot_html,
1009
+ memory_plot_html,
1010
+ nexus_plot_html,
1011
  )
1012
 
1013