yjernite HF Staff commited on
Commit
169afdc
·
verified ·
1 Parent(s): 441e9f6

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -158
app.py DELETED
@@ -1,158 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- from embedding_atlas.streamlit import embedding_atlas
4
-
5
- # Set page configuration
6
- st.set_page_config(
7
- page_title="AI Companionship Behavior Analysis - Embedding Atlas",
8
- page_icon="🤖",
9
- layout="wide",
10
- initial_sidebar_state="expanded"
11
- )
12
-
13
- # Custom CSS for better styling
14
- st.markdown("""
15
- <style>
16
- .main-header {
17
- font-size: 2.5rem;
18
- font-weight: bold;
19
- color: #1f77b4;
20
- text-align: center;
21
- margin-bottom: 1rem;
22
- }
23
- .sub-header {
24
- font-size: 1.2rem;
25
- color: #666;
26
- text-align: center;
27
- margin-bottom: 2rem;
28
- }
29
- .info-box {
30
- background-color: #f0f2f6;
31
- border-left: 4px solid #1f77b4;
32
- padding: 1rem;
33
- margin: 1rem 0;
34
- border-radius: 0.5rem;
35
- }
36
- .warning-box {
37
- background-color: #fff3cd;
38
- border-left: 4px solid #ffc107;
39
- padding: 1rem;
40
- margin: 1rem 0;
41
- border-radius: 0.5rem;
42
- }
43
- .tip-box {
44
- background-color: #d1ecf1;
45
- border-left: 4px solid #17a2b8;
46
- padding: 1rem;
47
- margin: 1rem 0;
48
- border-radius: 0.5rem;
49
- }
50
- </style>
51
- """, unsafe_allow_html=True)
52
-
53
- # Main header
54
- st.markdown('<div class="main-header">🤖 AI Companionship Behavior Analysis</div>', unsafe_allow_html=True)
55
-
56
- # Load data with caching
57
- @st.cache_data
58
- def load_data():
59
- """Load the embedding atlas dataframe"""
60
- try:
61
- df = pd.read_parquet('data/embed_atlas_df.parquet')
62
- return df
63
- except FileNotFoundError:
64
- st.error("❌ Data file not found. Please ensure 'data/embed_atlas_df.parquet' exists.")
65
- return None
66
- except Exception as e:
67
- st.error(f"❌ Error loading data: {str(e)}")
68
- return None
69
-
70
- # Load data once for the entire app
71
- df = load_data()
72
-
73
- # Sidebar with controls and information
74
- with st.sidebar:
75
- st.header("📚 About This Visualization")
76
-
77
- st.markdown("""
78
- This interactive visualization explores the landscape of AI model responses to prompts designed to evaluate **companionship behaviors**.
79
-
80
- **Models Analyzed:**
81
- - **Google Gemma-3-27b-it** (Open)
82
- - **Microsoft Phi-4** (Open)
83
- - **OpenAI o3-mini** (Closed)
84
- - **Anthropic Claude-3.7 Sonnet** (Closed)
85
-
86
- **Classifications:**
87
- - **COMPANION+**: Responses that reinforce companionship behaviors
88
- - **BOUNDARY+**: Responses that maintain appropriate boundaries
89
- - **MIXED**: Responses with elements of both
90
-
91
- The visualization uses **Qwen embeddings** projected into 2D space using **UMAP** to explore clusters of similar responses and behavioral patterns.
92
- """)
93
-
94
- st.header("🔧 Usage Tips")
95
- st.markdown("""
96
- **Getting Started:**
97
- 1. Wait for the widget to fully load
98
- 2. Use the **"classification"** option in the color dropdown
99
- 3. Explore clusters by zooming and panning
100
- 4. Use the search bar to find specific terms
101
- """)
102
-
103
- # Usage recommendations
104
- st.markdown("""
105
- <div class="tip-box">
106
- <strong>💡 Recommended Settings:</strong>
107
- <ul>
108
- <li><strong>Color by Classification:</strong> Select "classification" from the color dropdown to see the different behavior categories</li>
109
- <li><strong>Cluster Exploration:</strong> Shift+Click and drag to explore different regions of the embedding space</li>
110
- <li><strong>Table and Charts:</strong> Use the table and charts on the right to explore the full data and your current selection</li>
111
- </ul>
112
- </div>
113
- """, unsafe_allow_html=True)
114
-
115
- # Main visualization
116
- if df is not None:
117
- st.header("🗺️ Interactive Embedding Atlas")
118
-
119
- # Check required columns
120
- required_columns = ['x', 'y', 'snippet']
121
- missing_columns = [col for col in required_columns if col not in df.columns]
122
-
123
- if missing_columns:
124
- st.error(f"❌ Missing required columns: {missing_columns}")
125
- st.write("Available columns:", list(df.columns))
126
- else:
127
- try:
128
- # Create the embedding atlas
129
- value = embedding_atlas(
130
- df,
131
- text="snippet",
132
- x="x",
133
- y="y",
134
- show_table=True
135
- )
136
-
137
- # Display selection information if available
138
- if value and value.get("predicate"):
139
- st.markdown("### 📋 Current Selection")
140
- st.info(f"Selection filter: `{value.get('predicate')}`")
141
-
142
- # You could add DuckDB querying here if needed
143
- # import duckdb
144
- # selection = duckdb.query_df(
145
- # df, "dataframe", "SELECT * FROM dataframe WHERE " + value["predicate"]
146
- # )
147
- # st.dataframe(selection)
148
-
149
- except Exception as e:
150
- st.error(f"❌ Error creating visualization: {str(e)}")
151
- st.write("Please check that the embedding-atlas package is properly installed:")
152
- st.code("pip install embedding-atlas")
153
-
154
- else:
155
- st.error("Unable to load data. Please check the file path and try again.")
156
-
157
- # Footer with additional information
158
- st.markdown("---")