Update app.py
Browse files
app.py
CHANGED
|
@@ -736,7 +736,7 @@ def predict(message, history, max_tokens):
|
|
| 736 |
|
| 737 |
global_metrics.update(partial_output.replace("[COLLECTIVE] ", ""), confidence=avg_conf, prob_entropy=ent, hnm=hnm, hva=hva, resonance=avg_sim)
|
| 738 |
|
| 739 |
-
yield partial_output
|
| 740 |
|
| 741 |
if next_token_id.item() == tokenizer1.eos_token_id:
|
| 742 |
break
|
|
@@ -819,7 +819,7 @@ def predict(message, history, max_tokens):
|
|
| 819 |
})
|
| 820 |
if len(token_timing_log) > 1000: token_timing_log.pop(0)
|
| 821 |
|
| 822 |
-
yield accumulated_response
|
| 823 |
|
| 824 |
if next_token_id.item() == tok.eos_token_id:
|
| 825 |
break
|
|
@@ -833,8 +833,7 @@ def predict(message, history, max_tokens):
|
|
| 833 |
feedback_engine.cleanup()
|
| 834 |
cleanup()
|
| 835 |
|
| 836 |
-
def get_metrics_plot():
|
| 837 |
-
history = global_metrics.metric_history
|
| 838 |
if not history or len(history) < 1:
|
| 839 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 840 |
ax.text(0.5, 0.5, "Waiting for data...", ha='center', va='center')
|
|
@@ -868,8 +867,7 @@ def get_metrics_plot():
|
|
| 868 |
plt.tight_layout()
|
| 869 |
return fig
|
| 870 |
|
| 871 |
-
def get_correlation_plot():
|
| 872 |
-
history = global_metrics.metric_history
|
| 873 |
if len(history) < 2:
|
| 874 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 875 |
ax.text(0.5, 0.5, "More data points needed for correlation...", ha='center', va='center')
|
|
@@ -893,7 +891,7 @@ def get_correlation_plot():
|
|
| 893 |
plt.tight_layout()
|
| 894 |
return fig
|
| 895 |
|
| 896 |
-
def get_logos_matrix_plot():
|
| 897 |
if not token_analytics_log or len(token_analytics_log) < 3:
|
| 898 |
fig, ax = plt.subplots(figsize=(10, 5))
|
| 899 |
ax.text(0.5, 0.5, "More token generation needed for Logos Matrix...", ha='center', va='center')
|
|
@@ -928,7 +926,7 @@ def get_logos_matrix_plot():
|
|
| 928 |
plt.tight_layout()
|
| 929 |
return fig
|
| 930 |
|
| 931 |
-
def get_tsne_logos_plot():
|
| 932 |
if not hidden_state_log or len(hidden_state_log) < 5:
|
| 933 |
fig, ax = plt.subplots(figsize=(10, 5))
|
| 934 |
ax.text(0.5, 0.5, "Waiting for more vectors for t-SNE...", ha='center', va='center')
|
|
@@ -960,7 +958,7 @@ def get_tsne_logos_plot():
|
|
| 960 |
plt.tight_layout()
|
| 961 |
return fig
|
| 962 |
|
| 963 |
-
def get_resonance_plot():
|
| 964 |
if not resonance_history:
|
| 965 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 966 |
ax.text(0.5, 0.5, "Waiting for resonance data...", ha='center', va='center')
|
|
@@ -983,8 +981,7 @@ def get_resonance_plot():
|
|
| 983 |
plt.tight_layout()
|
| 984 |
return fig
|
| 985 |
|
| 986 |
-
def get_hidden_signals_plot():
|
| 987 |
-
history = global_metrics.metric_history
|
| 988 |
if not history or 'HNM' not in history[0]:
|
| 989 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 990 |
ax.text(0.5, 0.5, "Waiting for neural signals...", ha='center', va='center')
|
|
@@ -1005,9 +1002,9 @@ def get_hidden_signals_plot():
|
|
| 1005 |
plt.tight_layout()
|
| 1006 |
return fig
|
| 1007 |
|
| 1008 |
-
def get_neural_status():
|
| 1009 |
-
if not
|
| 1010 |
-
lat =
|
| 1011 |
hnm, hva = lat.get('HNM', 0), lat.get('HVA', 0)
|
| 1012 |
|
| 1013 |
if hva > 0.8: return "NEURAL CHAOS / HIGH DISSIPATION"
|
|
@@ -1017,7 +1014,7 @@ def get_neural_status():
|
|
| 1017 |
return "STABLE RESONANCE"
|
| 1018 |
|
| 1019 |
def chat_wrapper(message, history, max_tokens):
|
| 1020 |
-
for response in predict(message, history, max_tokens):
|
| 1021 |
yield response
|
| 1022 |
|
| 1023 |
with gr.Blocks(title="THE FATES - Triune Dashboard") as demo:
|
|
@@ -1079,23 +1076,37 @@ with gr.Blocks(title="THE FATES - Triune Dashboard") as demo:
|
|
| 1079 |
if chat_history is None:
|
| 1080 |
chat_history = []
|
| 1081 |
new_history = chat_history + [{"role": "user", "content": message}]
|
| 1082 |
-
for response in predict(message, chat_history, max_tokens):
|
| 1083 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1084 |
|
| 1085 |
-
|
| 1086 |
-
|
|
|
|
|
|
|
| 1087 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 1088 |
|
| 1089 |
refresh_btn.click(
|
| 1090 |
lambda: (
|
| 1091 |
global_metrics.get_current_metrics(),
|
| 1092 |
f"{resonance_history[-1]['AVG']:.2f}%" if resonance_history else "0.00%",
|
| 1093 |
-
get_neural_status(),
|
| 1094 |
phenom_engine.get_summary(),
|
| 1095 |
-
get_resonance_plot(),
|
| 1096 |
-
get_hidden_signals_plot(),
|
| 1097 |
-
get_metrics_plot(),
|
| 1098 |
-
get_correlation_plot(),
|
| 1099 |
pd.DataFrame(global_metrics.metric_history).tail(10)
|
| 1100 |
),
|
| 1101 |
None,
|
|
@@ -1103,7 +1114,7 @@ with gr.Blocks(title="THE FATES - Triune Dashboard") as demo:
|
|
| 1103 |
)
|
| 1104 |
|
| 1105 |
logos_refresh_btn.click(
|
| 1106 |
-
lambda: (get_logos_matrix_plot(), get_tsne_logos_plot(), pd.DataFrame(token_analytics_log).tail(50)),
|
| 1107 |
None,
|
| 1108 |
[logos_plot, tsne_plot, token_analytics_df]
|
| 1109 |
)
|
|
|
|
| 736 |
|
| 737 |
global_metrics.update(partial_output.replace("[COLLECTIVE] ", ""), confidence=avg_conf, prob_entropy=ent, hnm=hnm, hva=hva, resonance=avg_sim)
|
| 738 |
|
| 739 |
+
yield partial_output, global_metrics.metric_history, resonance_history, token_analytics_log, hidden_state_log, phenom_engine.get_summary()
|
| 740 |
|
| 741 |
if next_token_id.item() == tokenizer1.eos_token_id:
|
| 742 |
break
|
|
|
|
| 819 |
})
|
| 820 |
if len(token_timing_log) > 1000: token_timing_log.pop(0)
|
| 821 |
|
| 822 |
+
yield accumulated_response, global_metrics.metric_history, resonance_history, token_analytics_log, hidden_state_log, phenom_engine.get_summary()
|
| 823 |
|
| 824 |
if next_token_id.item() == tok.eos_token_id:
|
| 825 |
break
|
|
|
|
| 833 |
feedback_engine.cleanup()
|
| 834 |
cleanup()
|
| 835 |
|
| 836 |
+
def get_metrics_plot(history):
|
|
|
|
| 837 |
if not history or len(history) < 1:
|
| 838 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 839 |
ax.text(0.5, 0.5, "Waiting for data...", ha='center', va='center')
|
|
|
|
| 867 |
plt.tight_layout()
|
| 868 |
return fig
|
| 869 |
|
| 870 |
+
def get_correlation_plot(history):
|
|
|
|
| 871 |
if len(history) < 2:
|
| 872 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 873 |
ax.text(0.5, 0.5, "More data points needed for correlation...", ha='center', va='center')
|
|
|
|
| 891 |
plt.tight_layout()
|
| 892 |
return fig
|
| 893 |
|
| 894 |
+
def get_logos_matrix_plot(token_analytics_log):
|
| 895 |
if not token_analytics_log or len(token_analytics_log) < 3:
|
| 896 |
fig, ax = plt.subplots(figsize=(10, 5))
|
| 897 |
ax.text(0.5, 0.5, "More token generation needed for Logos Matrix...", ha='center', va='center')
|
|
|
|
| 926 |
plt.tight_layout()
|
| 927 |
return fig
|
| 928 |
|
| 929 |
+
def get_tsne_logos_plot(hidden_state_log):
|
| 930 |
if not hidden_state_log or len(hidden_state_log) < 5:
|
| 931 |
fig, ax = plt.subplots(figsize=(10, 5))
|
| 932 |
ax.text(0.5, 0.5, "Waiting for more vectors for t-SNE...", ha='center', va='center')
|
|
|
|
| 958 |
plt.tight_layout()
|
| 959 |
return fig
|
| 960 |
|
| 961 |
+
def get_resonance_plot(resonance_history):
|
| 962 |
if not resonance_history:
|
| 963 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 964 |
ax.text(0.5, 0.5, "Waiting for resonance data...", ha='center', va='center')
|
|
|
|
| 981 |
plt.tight_layout()
|
| 982 |
return fig
|
| 983 |
|
| 984 |
+
def get_hidden_signals_plot(history):
|
|
|
|
| 985 |
if not history or 'HNM' not in history[0]:
|
| 986 |
fig, ax = plt.subplots(figsize=(10, 4))
|
| 987 |
ax.text(0.5, 0.5, "Waiting for neural signals...", ha='center', va='center')
|
|
|
|
| 1002 |
plt.tight_layout()
|
| 1003 |
return fig
|
| 1004 |
|
| 1005 |
+
def get_neural_status(metric_history):
|
| 1006 |
+
if not metric_history: return "AWAKENING..."
|
| 1007 |
+
lat = metric_history[-1]
|
| 1008 |
hnm, hva = lat.get('HNM', 0), lat.get('HVA', 0)
|
| 1009 |
|
| 1010 |
if hva > 0.8: return "NEURAL CHAOS / HIGH DISSIPATION"
|
|
|
|
| 1014 |
return "STABLE RESONANCE"
|
| 1015 |
|
| 1016 |
def chat_wrapper(message, history, max_tokens):
|
| 1017 |
+
for response, _, _, _, _, _ in predict(message, history, max_tokens):
|
| 1018 |
yield response
|
| 1019 |
|
| 1020 |
with gr.Blocks(title="THE FATES - Triune Dashboard") as demo:
|
|
|
|
| 1076 |
if chat_history is None:
|
| 1077 |
chat_history = []
|
| 1078 |
new_history = chat_history + [{"role": "user", "content": message}]
|
| 1079 |
+
for response, metric_hist, res_hist, token_log, hidden_log, phenom_summary in predict(message, chat_history, max_tokens):
|
| 1080 |
+
yield (
|
| 1081 |
+
"",
|
| 1082 |
+
new_history + [{"role": "assistant", "content": response}],
|
| 1083 |
+
metric_hist[-1] if metric_hist else {},
|
| 1084 |
+
f"{res_hist[-1]['AVG']:.2f}%" if res_hist else "0.00%",
|
| 1085 |
+
get_neural_status(metric_hist),
|
| 1086 |
+
phenom_summary,
|
| 1087 |
+
get_resonance_plot(res_hist),
|
| 1088 |
+
get_hidden_signals_plot(metric_hist),
|
| 1089 |
+
get_metrics_plot(metric_hist),
|
| 1090 |
+
get_correlation_plot(metric_hist),
|
| 1091 |
+
pd.DataFrame(metric_hist).tail(10)
|
| 1092 |
+
)
|
| 1093 |
|
| 1094 |
+
outputs = [msg, chatbot, live_metrics_json, resonance_lbl, neural_status_lbl, phenom_state_txt, resonance_plot, neural_dynamics_plot, trends_plot, corr_plot, metrics_table]
|
| 1095 |
+
|
| 1096 |
+
submit.click(handle_submit, [msg, chatbot, max_tokens_slider], outputs)
|
| 1097 |
+
msg.submit(handle_submit, [msg, chatbot, max_tokens_slider], outputs)
|
| 1098 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 1099 |
|
| 1100 |
refresh_btn.click(
|
| 1101 |
lambda: (
|
| 1102 |
global_metrics.get_current_metrics(),
|
| 1103 |
f"{resonance_history[-1]['AVG']:.2f}%" if resonance_history else "0.00%",
|
| 1104 |
+
get_neural_status(global_metrics.metric_history),
|
| 1105 |
phenom_engine.get_summary(),
|
| 1106 |
+
get_resonance_plot(resonance_history),
|
| 1107 |
+
get_hidden_signals_plot(global_metrics.metric_history),
|
| 1108 |
+
get_metrics_plot(global_metrics.metric_history),
|
| 1109 |
+
get_correlation_plot(global_metrics.metric_history),
|
| 1110 |
pd.DataFrame(global_metrics.metric_history).tail(10)
|
| 1111 |
),
|
| 1112 |
None,
|
|
|
|
| 1114 |
)
|
| 1115 |
|
| 1116 |
logos_refresh_btn.click(
|
| 1117 |
+
lambda: (get_logos_matrix_plot(token_analytics_log), get_tsne_logos_plot(hidden_state_log), pd.DataFrame(token_analytics_log).tail(50)),
|
| 1118 |
None,
|
| 1119 |
[logos_plot, tsne_plot, token_analytics_df]
|
| 1120 |
)
|