Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -732,10 +732,296 @@ def create_entropy_geometry_plot(phi: np.ndarray):
|
|
732 |
|
733 |
return fig
|
734 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
def update_manifold_visualization(species_selection, emotion_selection, lens_selection,
|
736 |
alpha_min, alpha_max, srl_min, srl_max,
|
737 |
point_size, show_boundary, show_trajectories, color_scheme):
|
738 |
-
"""Update manifold
|
739 |
|
740 |
df_filtered = df_combined.copy()
|
741 |
|
@@ -765,28 +1051,102 @@ def update_manifold_visualization(species_selection, emotion_selection, lens_sel
|
|
765 |
text="No data points match the current filters",
|
766 |
xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False
|
767 |
)
|
768 |
-
|
|
|
769 |
|
770 |
-
|
|
|
771 |
df_filtered, lens_selection, color_scheme, point_size,
|
772 |
show_boundary, show_trajectories
|
773 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
774 |
|
775 |
# ---------------------------------------------------------------
|
776 |
# Gradio Interface
|
777 |
# ---------------------------------------------------------------
|
778 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) as demo:
|
779 |
gr.Markdown("""
|
780 |
-
# π **CMT Holographic Information Geometry Engine**
|
781 |
-
*
|
782 |
-
|
783 |
-
|
784 |
-
-
|
785 |
-
- Cross-species communication mapping
|
786 |
-
-
|
787 |
-
-
|
788 |
-
-
|
789 |
-
-
|
|
|
|
|
|
|
790 |
""")
|
791 |
|
792 |
with gr.Tabs():
|
@@ -830,9 +1190,26 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) a
|
|
830 |
choices=["Species", "Emotion", "CMT_Alpha", "CMT_SRL", "Cluster"],
|
831 |
value="Species"
|
832 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
|
834 |
with gr.Column(scale=3):
|
835 |
manifold_plot = gr.Plot(label="Universal Communication Manifold")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
836 |
|
837 |
# Wire up events
|
838 |
manifold_inputs = [
|
@@ -841,12 +1218,27 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) a
|
|
841 |
point_size, show_species_boundary, show_trajectories, color_scheme
|
842 |
]
|
843 |
|
|
|
|
|
|
|
|
|
|
|
844 |
for component in manifold_inputs:
|
845 |
component.change(
|
846 |
update_manifold_visualization,
|
847 |
inputs=manifold_inputs,
|
848 |
-
outputs=
|
849 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
850 |
|
851 |
with gr.TabItem("π¬ Interactive Holography"):
|
852 |
with gr.Row():
|
@@ -1004,6 +1396,25 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) a
|
|
1004 |
outputs=cross_species_outputs
|
1005 |
)
|
1006 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1007 |
print("β
CMT Holographic Visualization Suite Ready!")
|
1008 |
|
1009 |
if __name__ == "__main__":
|
|
|
732 |
|
733 |
return fig
|
734 |
|
735 |
+
def create_2d_projection_plot(df_filtered, lens_selected, color_scheme):
|
736 |
+
"""Create 2D projection plot."""
|
737 |
+
alpha_col = f"diag_alpha_{lens_selected}"
|
738 |
+
srl_col = f"diag_srl_{lens_selected}"
|
739 |
+
|
740 |
+
# Color mapping
|
741 |
+
if color_scheme == "Species":
|
742 |
+
color_values = [1 if s == "Human" else 0 for s in df_filtered['source']]
|
743 |
+
colorscale = [[0, '#1f77b4'], [1, '#ff7f0e']]
|
744 |
+
colorbar_title = "Species"
|
745 |
+
elif color_scheme == "Emotion":
|
746 |
+
unique_emotions = df_filtered['label'].unique()
|
747 |
+
emotion_map = {emotion: i for i, emotion in enumerate(unique_emotions)}
|
748 |
+
color_values = [emotion_map[label] for label in df_filtered['label']]
|
749 |
+
colorscale = 'Viridis'
|
750 |
+
colorbar_title = "Emotional State"
|
751 |
+
else:
|
752 |
+
color_values = df_filtered['cluster'].values
|
753 |
+
colorscale = 'Plotly3'
|
754 |
+
colorbar_title = "Cluster"
|
755 |
+
|
756 |
+
fig = go.Figure()
|
757 |
+
|
758 |
+
fig.add_trace(go.Scatter(
|
759 |
+
x=df_filtered['x'],
|
760 |
+
y=df_filtered['y'],
|
761 |
+
mode='markers',
|
762 |
+
marker=dict(
|
763 |
+
size=8,
|
764 |
+
color=color_values,
|
765 |
+
colorscale=colorscale,
|
766 |
+
showscale=True,
|
767 |
+
colorbar=dict(title=colorbar_title),
|
768 |
+
opacity=0.7,
|
769 |
+
line=dict(width=0.5, color='rgba(50,50,50,0.5)')
|
770 |
+
),
|
771 |
+
text=[f"{row['source']}: {row['label']}" for _, row in df_filtered.iterrows()],
|
772 |
+
name='Communications'
|
773 |
+
))
|
774 |
+
|
775 |
+
fig.update_layout(
|
776 |
+
title="2D Manifold Projection",
|
777 |
+
xaxis_title='Dimension 1',
|
778 |
+
yaxis_title='Dimension 2',
|
779 |
+
margin=dict(l=0, r=0, b=0, t=40)
|
780 |
+
)
|
781 |
+
|
782 |
+
return fig
|
783 |
+
|
784 |
+
def create_density_heatmap(df_filtered):
|
785 |
+
"""Create density heatmap."""
|
786 |
+
from scipy.stats import gaussian_kde
|
787 |
+
|
788 |
+
if len(df_filtered) < 10:
|
789 |
+
return go.Figure(layout={"title": "Insufficient data for density plot"})
|
790 |
+
|
791 |
+
x = df_filtered['x'].values
|
792 |
+
y = df_filtered['y'].values
|
793 |
+
|
794 |
+
# Create density estimation
|
795 |
+
try:
|
796 |
+
kde = gaussian_kde(np.vstack([x, y]))
|
797 |
+
|
798 |
+
# Create grid
|
799 |
+
x_range = np.linspace(x.min(), x.max(), 50)
|
800 |
+
y_range = np.linspace(y.min(), y.max(), 50)
|
801 |
+
X, Y = np.meshgrid(x_range, y_range)
|
802 |
+
positions = np.vstack([X.ravel(), Y.ravel()])
|
803 |
+
Z = kde(positions).reshape(X.shape)
|
804 |
+
|
805 |
+
fig = go.Figure(data=go.Heatmap(
|
806 |
+
x=x_range,
|
807 |
+
y=y_range,
|
808 |
+
z=Z,
|
809 |
+
colorscale='Viridis',
|
810 |
+
showscale=True
|
811 |
+
))
|
812 |
+
|
813 |
+
# Add scatter points
|
814 |
+
fig.add_trace(go.Scatter(
|
815 |
+
x=x, y=y,
|
816 |
+
mode='markers',
|
817 |
+
marker=dict(size=4, color='white', opacity=0.8),
|
818 |
+
name='Data Points'
|
819 |
+
))
|
820 |
+
|
821 |
+
fig.update_layout(
|
822 |
+
title="Communication Density Landscape",
|
823 |
+
xaxis_title='Dimension 1',
|
824 |
+
yaxis_title='Dimension 2',
|
825 |
+
margin=dict(l=0, r=0, b=0, t=40)
|
826 |
+
)
|
827 |
+
|
828 |
+
return fig
|
829 |
+
except:
|
830 |
+
return go.Figure(layout={"title": "Could not create density plot"})
|
831 |
+
|
832 |
+
def create_feature_distributions(df_filtered, lens_selected):
|
833 |
+
"""Create feature distribution plots."""
|
834 |
+
alpha_col = f"diag_alpha_{lens_selected}"
|
835 |
+
srl_col = f"diag_srl_{lens_selected}"
|
836 |
+
|
837 |
+
fig = make_subplots(
|
838 |
+
rows=2, cols=2,
|
839 |
+
subplot_titles=(
|
840 |
+
f"Alpha Distribution ({lens_selected})",
|
841 |
+
f"SRL Distribution ({lens_selected})",
|
842 |
+
"Species Distribution",
|
843 |
+
"Emotion Distribution"
|
844 |
+
),
|
845 |
+
specs=[[{"type": "histogram"}, {"type": "histogram"}],
|
846 |
+
[{"type": "bar"}, {"type": "bar"}]]
|
847 |
+
)
|
848 |
+
|
849 |
+
# Alpha distribution
|
850 |
+
if alpha_col in df_filtered.columns:
|
851 |
+
fig.add_trace(go.Histogram(
|
852 |
+
x=df_filtered[alpha_col],
|
853 |
+
name="Alpha",
|
854 |
+
nbinsx=30,
|
855 |
+
marker_color='lightblue'
|
856 |
+
), row=1, col=1)
|
857 |
+
|
858 |
+
# SRL distribution
|
859 |
+
if srl_col in df_filtered.columns:
|
860 |
+
fig.add_trace(go.Histogram(
|
861 |
+
x=df_filtered[srl_col],
|
862 |
+
name="SRL",
|
863 |
+
nbinsx=30,
|
864 |
+
marker_color='lightgreen'
|
865 |
+
), row=1, col=2)
|
866 |
+
|
867 |
+
# Species distribution
|
868 |
+
species_counts = df_filtered['source'].value_counts()
|
869 |
+
fig.add_trace(go.Bar(
|
870 |
+
x=species_counts.index,
|
871 |
+
y=species_counts.values,
|
872 |
+
name="Species",
|
873 |
+
marker_color=['#1f77b4', '#ff7f0e']
|
874 |
+
), row=2, col=1)
|
875 |
+
|
876 |
+
# Emotion distribution
|
877 |
+
emotion_counts = df_filtered['label'].value_counts().head(10)
|
878 |
+
fig.add_trace(go.Bar(
|
879 |
+
x=emotion_counts.index,
|
880 |
+
y=emotion_counts.values,
|
881 |
+
name="Emotions",
|
882 |
+
marker_color='lightcoral'
|
883 |
+
), row=2, col=2)
|
884 |
+
|
885 |
+
fig.update_layout(
|
886 |
+
title_text="Statistical Distributions",
|
887 |
+
showlegend=False,
|
888 |
+
margin=dict(l=0, r=0, b=0, t=60)
|
889 |
+
)
|
890 |
+
|
891 |
+
return fig
|
892 |
+
|
893 |
+
def create_cluster_analysis(df_filtered):
|
894 |
+
"""Create cluster analysis visualization."""
|
895 |
+
fig = make_subplots(
|
896 |
+
rows=1, cols=2,
|
897 |
+
subplot_titles=("Cluster Distribution", "Cluster Composition"),
|
898 |
+
specs=[[{"type": "bar"}, {"type": "bar"}]]
|
899 |
+
)
|
900 |
+
|
901 |
+
# Cluster distribution
|
902 |
+
cluster_counts = df_filtered['cluster'].value_counts().sort_index()
|
903 |
+
fig.add_trace(go.Bar(
|
904 |
+
x=[f"C{i}" for i in cluster_counts.index],
|
905 |
+
y=cluster_counts.values,
|
906 |
+
name="Cluster Size",
|
907 |
+
marker_color='skyblue'
|
908 |
+
), row=1, col=1)
|
909 |
+
|
910 |
+
# Species composition per cluster
|
911 |
+
cluster_species = df_filtered.groupby(['cluster', 'source']).size().unstack(fill_value=0)
|
912 |
+
if len(cluster_species.columns) > 0:
|
913 |
+
for species in cluster_species.columns:
|
914 |
+
fig.add_trace(go.Bar(
|
915 |
+
x=[f"C{i}" for i in cluster_species.index],
|
916 |
+
y=cluster_species[species],
|
917 |
+
name=species,
|
918 |
+
marker_color='#1f77b4' if species == 'Human' else '#ff7f0e'
|
919 |
+
), row=1, col=2)
|
920 |
+
|
921 |
+
fig.update_layout(
|
922 |
+
title_text="Cluster Analysis",
|
923 |
+
margin=dict(l=0, r=0, b=0, t=60)
|
924 |
+
)
|
925 |
+
|
926 |
+
return fig
|
927 |
+
|
928 |
+
def create_similarity_matrix(df_filtered, lens_selected):
|
929 |
+
"""Create species similarity matrix."""
|
930 |
+
alpha_col = f"diag_alpha_{lens_selected}"
|
931 |
+
srl_col = f"diag_srl_{lens_selected}"
|
932 |
+
|
933 |
+
# Calculate mean values for each species-emotion combination
|
934 |
+
similarity_data = []
|
935 |
+
|
936 |
+
for species in df_filtered['source'].unique():
|
937 |
+
for emotion in df_filtered['label'].unique():
|
938 |
+
subset = df_filtered[(df_filtered['source'] == species) & (df_filtered['label'] == emotion)]
|
939 |
+
if len(subset) > 0:
|
940 |
+
alpha_mean = subset[alpha_col].mean() if alpha_col in subset.columns else 0
|
941 |
+
srl_mean = subset[srl_col].mean() if srl_col in subset.columns else 0
|
942 |
+
similarity_data.append({
|
943 |
+
'species': species,
|
944 |
+
'emotion': emotion,
|
945 |
+
'alpha': alpha_mean,
|
946 |
+
'srl': srl_mean,
|
947 |
+
'combined': alpha_mean + srl_mean
|
948 |
+
})
|
949 |
+
|
950 |
+
if not similarity_data:
|
951 |
+
return go.Figure(layout={"title": "No data for similarity matrix"})
|
952 |
+
|
953 |
+
similarity_df = pd.DataFrame(similarity_data)
|
954 |
+
pivot_table = similarity_df.pivot(index='emotion', columns='species', values='combined')
|
955 |
+
|
956 |
+
fig = go.Figure(data=go.Heatmap(
|
957 |
+
z=pivot_table.values,
|
958 |
+
x=pivot_table.columns,
|
959 |
+
y=pivot_table.index,
|
960 |
+
colorscale='RdYlBu_r',
|
961 |
+
showscale=True,
|
962 |
+
colorbar=dict(title="Similarity Score")
|
963 |
+
))
|
964 |
+
|
965 |
+
fig.update_layout(
|
966 |
+
title="Cross-Species Similarity Matrix",
|
967 |
+
margin=dict(l=0, r=0, b=0, t=40)
|
968 |
+
)
|
969 |
+
|
970 |
+
return fig
|
971 |
+
|
972 |
+
def calculate_live_statistics(df_filtered, lens_selected):
|
973 |
+
"""Calculate live statistics for the dataset."""
|
974 |
+
alpha_col = f"diag_alpha_{lens_selected}"
|
975 |
+
srl_col = f"diag_srl_{lens_selected}"
|
976 |
+
|
977 |
+
stats = {
|
978 |
+
'total_samples': len(df_filtered),
|
979 |
+
'species_counts': df_filtered['source'].value_counts().to_dict(),
|
980 |
+
'emotion_counts': len(df_filtered['label'].unique()),
|
981 |
+
'cluster_count': len(df_filtered['cluster'].unique())
|
982 |
+
}
|
983 |
+
|
984 |
+
if alpha_col in df_filtered.columns:
|
985 |
+
stats['alpha_mean'] = df_filtered[alpha_col].mean()
|
986 |
+
stats['alpha_std'] = df_filtered[alpha_col].std()
|
987 |
+
|
988 |
+
if srl_col in df_filtered.columns:
|
989 |
+
stats['srl_mean'] = df_filtered[srl_col].mean()
|
990 |
+
stats['srl_std'] = df_filtered[srl_col].std()
|
991 |
+
|
992 |
+
# Format as HTML
|
993 |
+
html_content = f"""
|
994 |
+
<div style="padding: 10px; background-color: #f0f8ff; border-radius: 8px;">
|
995 |
+
<h4>π Live Dataset Statistics</h4>
|
996 |
+
<p><strong>Total Samples:</strong> {stats['total_samples']}</p>
|
997 |
+
<p><strong>Species:</strong>
|
998 |
+
{' | '.join([f"{k}: {v}" for k, v in stats['species_counts'].items()])}
|
999 |
+
</p>
|
1000 |
+
<p><strong>Emotions:</strong> {stats['emotion_counts']}</p>
|
1001 |
+
<p><strong>Clusters:</strong> {stats['cluster_count']}</p>
|
1002 |
+
"""
|
1003 |
+
|
1004 |
+
if 'alpha_mean' in stats:
|
1005 |
+
html_content += f"""
|
1006 |
+
<p><strong>Alpha ({lens_selected}):</strong>
|
1007 |
+
ΞΌ={stats['alpha_mean']:.3f}, Ο={stats['alpha_std']:.3f}
|
1008 |
+
</p>
|
1009 |
+
"""
|
1010 |
+
|
1011 |
+
if 'srl_mean' in stats:
|
1012 |
+
html_content += f"""
|
1013 |
+
<p><strong>SRL ({lens_selected}):</strong>
|
1014 |
+
ΞΌ={stats['srl_mean']:.3f}, Ο={stats['srl_std']:.3f}
|
1015 |
+
</p>
|
1016 |
+
"""
|
1017 |
+
|
1018 |
+
html_content += "</div>"
|
1019 |
+
return html_content
|
1020 |
+
|
1021 |
def update_manifold_visualization(species_selection, emotion_selection, lens_selection,
|
1022 |
alpha_min, alpha_max, srl_min, srl_max,
|
1023 |
point_size, show_boundary, show_trajectories, color_scheme):
|
1024 |
+
"""Update all manifold visualizations with filters."""
|
1025 |
|
1026 |
df_filtered = df_combined.copy()
|
1027 |
|
|
|
1051 |
text="No data points match the current filters",
|
1052 |
xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False
|
1053 |
)
|
1054 |
+
empty_stats = "<p>No data available</p>"
|
1055 |
+
return empty_fig, empty_fig, empty_fig, empty_fig, empty_fig, empty_fig, empty_stats
|
1056 |
|
1057 |
+
# Create all visualizations
|
1058 |
+
main_plot = create_enhanced_manifold_plot(
|
1059 |
df_filtered, lens_selection, color_scheme, point_size,
|
1060 |
show_boundary, show_trajectories
|
1061 |
)
|
1062 |
+
|
1063 |
+
projection_2d = create_2d_projection_plot(df_filtered, lens_selection, color_scheme)
|
1064 |
+
density_plot = create_density_heatmap(df_filtered)
|
1065 |
+
feature_dists = create_feature_distributions(df_filtered, lens_selection)
|
1066 |
+
cluster_plot = create_cluster_analysis(df_filtered)
|
1067 |
+
similarity_plot = create_similarity_matrix(df_filtered, lens_selection)
|
1068 |
+
stats_html = calculate_live_statistics(df_filtered, lens_selection)
|
1069 |
+
|
1070 |
+
return main_plot, projection_2d, density_plot, feature_dists, cluster_plot, similarity_plot, stats_html
|
1071 |
+
|
1072 |
+
def export_filtered_data(species_selection, emotion_selection, lens_selection,
|
1073 |
+
alpha_min, alpha_max, srl_min, srl_max):
|
1074 |
+
"""Export filtered dataset for analysis."""
|
1075 |
+
import tempfile
|
1076 |
+
import json
|
1077 |
+
|
1078 |
+
df_filtered = df_combined.copy()
|
1079 |
+
|
1080 |
+
if species_selection:
|
1081 |
+
df_filtered = df_filtered[df_filtered['source'].isin(species_selection)]
|
1082 |
+
|
1083 |
+
if emotion_selection:
|
1084 |
+
df_filtered = df_filtered[df_filtered['label'].isin(emotion_selection)]
|
1085 |
+
|
1086 |
+
alpha_col = f"diag_alpha_{lens_selection}"
|
1087 |
+
srl_col = f"diag_srl_{lens_selection}"
|
1088 |
+
|
1089 |
+
if alpha_col in df_filtered.columns:
|
1090 |
+
df_filtered = df_filtered[
|
1091 |
+
(df_filtered[alpha_col] >= alpha_min) &
|
1092 |
+
(df_filtered[alpha_col] <= alpha_max)
|
1093 |
+
]
|
1094 |
+
|
1095 |
+
if srl_col in df_filtered.columns:
|
1096 |
+
df_filtered = df_filtered[
|
1097 |
+
(df_filtered[srl_col] >= srl_min) &
|
1098 |
+
(df_filtered[srl_col] <= srl_max)
|
1099 |
+
]
|
1100 |
+
|
1101 |
+
if len(df_filtered) == 0:
|
1102 |
+
return "<p style='color: red;'>β No data to export with current filters</p>"
|
1103 |
+
|
1104 |
+
# Create export summary
|
1105 |
+
export_summary = {
|
1106 |
+
"export_timestamp": pd.Timestamp.now().isoformat(),
|
1107 |
+
"total_samples": len(df_filtered),
|
1108 |
+
"species_counts": df_filtered['source'].value_counts().to_dict(),
|
1109 |
+
"emotion_types": df_filtered['label'].unique().tolist(),
|
1110 |
+
"lens_used": lens_selection,
|
1111 |
+
"filters_applied": {
|
1112 |
+
"species": species_selection,
|
1113 |
+
"emotions": emotion_selection,
|
1114 |
+
"alpha_range": [alpha_min, alpha_max],
|
1115 |
+
"srl_range": [srl_min, srl_max]
|
1116 |
+
}
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
summary_html = f"""
|
1120 |
+
<div style="padding: 10px; background-color: #e8f5e8; border-radius: 8px; margin-top: 10px;">
|
1121 |
+
<h4>β
Export Ready</h4>
|
1122 |
+
<p><strong>Samples:</strong> {export_summary['total_samples']}</p>
|
1123 |
+
<p><strong>Species:</strong> {', '.join([f"{k}({v})" for k, v in export_summary['species_counts'].items()])}</p>
|
1124 |
+
<p><strong>Emotions:</strong> {len(export_summary['emotion_types'])} types</p>
|
1125 |
+
<p><strong>Lens:</strong> {lens_selection}</p>
|
1126 |
+
<p><em>Data ready for download via your browser's dev tools or notebook integration.</em></p>
|
1127 |
+
</div>
|
1128 |
+
"""
|
1129 |
+
|
1130 |
+
return summary_html
|
1131 |
|
1132 |
# ---------------------------------------------------------------
|
1133 |
# Gradio Interface
|
1134 |
# ---------------------------------------------------------------
|
1135 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) as demo:
|
1136 |
gr.Markdown("""
|
1137 |
+
# π **CMT Holographic Information Geometry Engine v5.0**
|
1138 |
+
*Revolutionary interspecies communication analysis platform*
|
1139 |
+
|
1140 |
+
**π Enhanced Features:**
|
1141 |
+
- **π Universal Manifold Explorer**: Multi-dimensional visualization suite with live statistics
|
1142 |
+
- **π¬ Interactive Holography**: Cross-species communication mapping with mathematical precision
|
1143 |
+
- **π Real-time Analytics**: Dynamic filtering, clustering, and similarity analysis
|
1144 |
+
- **π¨ Rich Visualizations**: 2D/3D plots, density heatmaps, feature distributions
|
1145 |
+
- **πΎ Data Export**: Export filtered datasets for external analysis
|
1146 |
+
- **β‘ Auto-loading**: Manifold visualizations load automatically on startup
|
1147 |
+
|
1148 |
+
---
|
1149 |
+
**π― Goal**: Map the geometric structure of communication to reveal universal patterns across species
|
1150 |
""")
|
1151 |
|
1152 |
with gr.Tabs():
|
|
|
1190 |
choices=["Species", "Emotion", "CMT_Alpha", "CMT_SRL", "Cluster"],
|
1191 |
value="Species"
|
1192 |
)
|
1193 |
+
|
1194 |
+
with gr.Accordion("π Live Statistics", open=True):
|
1195 |
+
stats_html = gr.HTML(label="Dataset Statistics")
|
1196 |
+
similarity_matrix = gr.Plot(label="Species Similarity Matrix")
|
1197 |
+
|
1198 |
+
with gr.Accordion("πΎ Data Export", open=False):
|
1199 |
+
gr.Markdown("**Export filtered dataset for further analysis**")
|
1200 |
+
export_button = gr.Button("π₯ Export Filtered Data", variant="secondary")
|
1201 |
+
export_status = gr.HTML("")
|
1202 |
|
1203 |
with gr.Column(scale=3):
|
1204 |
manifold_plot = gr.Plot(label="Universal Communication Manifold")
|
1205 |
+
|
1206 |
+
with gr.Row():
|
1207 |
+
projection_2d = gr.Plot(label="2D Projection")
|
1208 |
+
density_plot = gr.Plot(label="Density Heatmap")
|
1209 |
+
|
1210 |
+
with gr.Row():
|
1211 |
+
feature_distributions = gr.Plot(label="Feature Distributions")
|
1212 |
+
cluster_analysis = gr.Plot(label="Cluster Analysis")
|
1213 |
|
1214 |
# Wire up events
|
1215 |
manifold_inputs = [
|
|
|
1218 |
point_size, show_species_boundary, show_trajectories, color_scheme
|
1219 |
]
|
1220 |
|
1221 |
+
manifold_outputs = [
|
1222 |
+
manifold_plot, projection_2d, density_plot,
|
1223 |
+
feature_distributions, cluster_analysis, similarity_matrix, stats_html
|
1224 |
+
]
|
1225 |
+
|
1226 |
for component in manifold_inputs:
|
1227 |
component.change(
|
1228 |
update_manifold_visualization,
|
1229 |
inputs=manifold_inputs,
|
1230 |
+
outputs=manifold_outputs
|
1231 |
)
|
1232 |
+
|
1233 |
+
# Wire up export button
|
1234 |
+
export_button.click(
|
1235 |
+
export_filtered_data,
|
1236 |
+
inputs=[
|
1237 |
+
species_filter, emotion_filter, lens_selector,
|
1238 |
+
alpha_min, alpha_max, srl_min, srl_max
|
1239 |
+
],
|
1240 |
+
outputs=[export_status]
|
1241 |
+
)
|
1242 |
|
1243 |
with gr.TabItem("π¬ Interactive Holography"):
|
1244 |
with gr.Row():
|
|
|
1396 |
outputs=cross_species_outputs
|
1397 |
)
|
1398 |
|
1399 |
+
# Auto-load manifold visualizations on startup
|
1400 |
+
demo.load(
|
1401 |
+
update_manifold_visualization,
|
1402 |
+
inputs=[
|
1403 |
+
gr.State(["Human", "Dog"]), # species_filter default
|
1404 |
+
gr.State(list(df_combined['label'].unique())), # emotion_filter default
|
1405 |
+
gr.State("gamma"), # lens_selector default
|
1406 |
+
gr.State(0), # alpha_min default
|
1407 |
+
gr.State(5), # alpha_max default
|
1408 |
+
gr.State(0), # srl_min default
|
1409 |
+
gr.State(100), # srl_max default
|
1410 |
+
gr.State(6), # point_size default
|
1411 |
+
gr.State(True), # show_species_boundary default
|
1412 |
+
gr.State(False), # show_trajectories default
|
1413 |
+
gr.State("Species") # color_scheme default
|
1414 |
+
],
|
1415 |
+
outputs=manifold_outputs
|
1416 |
+
)
|
1417 |
+
|
1418 |
print("β
CMT Holographic Visualization Suite Ready!")
|
1419 |
|
1420 |
if __name__ == "__main__":
|