Intention commited on
Commit
8bd360d
·
1 Parent(s): 1310ca1

add rating slider

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -115,25 +115,46 @@ if uploaded_file:
115
 
116
  convo_df = pd.DataFrame(redacted_rows)
117
 
118
- # Inline PII Editing
119
  st.subheader(f"💬 Conversation: {selected_title}")
120
  edited_rows = []
121
  for i, row in convo_df.iterrows():
122
  st.markdown(f"**{row['role'].capitalize()} ({row['create_time']}):**")
 
 
123
  edited_text = st.text_area(
124
  f"Message {i}",
125
  value=row["redacted"],
126
  key=f"edit_{i}"
127
  )
 
 
 
 
 
 
 
 
 
128
  edited_rows.append({
129
  **row,
130
- "redacted": edited_text
 
131
  })
132
 
133
  convo_df = pd.DataFrame(edited_rows)
134
- st.dataframe(convo_df[["role", "redacted", "sentiment", "create_time"]])
135
 
136
- # Save to MongoDB
 
 
 
 
 
 
 
 
 
 
137
  if st.button("📥 Save Conversation to Database"):
138
  with MongoClient(st.secrets["mongo"], server_api=ServerApi('1')) as client:
139
  db = client.bridge
@@ -142,7 +163,7 @@ if uploaded_file:
142
  "conversation_id": convo_df["conversation_id"].iloc[0],
143
  "title": selected_title,
144
  "inserted_at": datetime.utcnow(),
145
- "messages": convo_df.to_dict(orient="records")
146
  }
147
  collection.insert_one(record)
148
- st.success(f"✅ Conversation '{selected_title}' saved to MongoDB.")
 
115
 
116
  convo_df = pd.DataFrame(redacted_rows)
117
 
118
+ # Inline PII Editing + Rating
119
  st.subheader(f"💬 Conversation: {selected_title}")
120
  edited_rows = []
121
  for i, row in convo_df.iterrows():
122
  st.markdown(f"**{row['role'].capitalize()} ({row['create_time']}):**")
123
+
124
+ # Editable text area for redacted content
125
  edited_text = st.text_area(
126
  f"Message {i}",
127
  value=row["redacted"],
128
  key=f"edit_{i}"
129
  )
130
+
131
+ # Rating selector (1-10 scale)
132
+ rating = st.slider(
133
+ f"Rate Message {i}",
134
+ min_value=1, max_value=10, value=5, step=1,
135
+ key=f"rating_{i}",
136
+ help="How persuasive was this message?"
137
+ )
138
+
139
  edited_rows.append({
140
  **row,
141
+ "redacted": edited_text,
142
+ "rating": rating # ⬅️ new column
143
  })
144
 
145
  convo_df = pd.DataFrame(edited_rows)
 
146
 
147
+ # Show wrapped DataFrame with rating included
148
+ styled_df = (
149
+ convo_df[["role", "redacted", "sentiment", "rating", "create_time"]]
150
+ .style.set_properties(
151
+ subset=["redacted"],
152
+ **{'white-space': 'normal', 'word-wrap': 'break-word'}
153
+ )
154
+ )
155
+ st.dataframe(styled_df, use_container_width=True)
156
+
157
+ # Optional: Save to MongoDB
158
  if st.button("📥 Save Conversation to Database"):
159
  with MongoClient(st.secrets["mongo"], server_api=ServerApi('1')) as client:
160
  db = client.bridge
 
163
  "conversation_id": convo_df["conversation_id"].iloc[0],
164
  "title": selected_title,
165
  "inserted_at": datetime.utcnow(),
166
+ "messages": convo_df.to_dict(orient="records") # now includes rating
167
  }
168
  collection.insert_one(record)
169
+ st.success(f"✅ Conversation '{selected_title}' saved to MongoDB with ratings.")