Intention commited on
Commit
b6b1f02
Β·
1 Parent(s): fdf8278

edit pii.

Browse files
Files changed (1) hide show
  1. app.py +34 -31
app.py CHANGED
@@ -9,10 +9,11 @@ from datetime import datetime
9
  from uuid import uuid4
10
 
11
  # -----------------------------
12
- # Consent Setup
13
  # -----------------------------
14
  st.set_page_config(page_title="ChatGPT Log Analyzer", page_icon="πŸ€–")
15
 
 
16
  if "consent" not in st.session_state:
17
  st.session_state.consent = ""
18
 
@@ -40,11 +41,21 @@ if st.session_state.consent == "Yes, I consent":
40
  st.session_state.id = datetime.now().strftime('%Y%m-%d%H-%M-') + str(uuid4())
41
  st.success("βœ… You consented to participate.")
42
  st.info(f"Your anonymized ID is: **{st.session_state.id}**. Keep this if you want your data deleted later.")
43
-
44
  elif st.session_state.consent == "No, I do not consent":
45
  placeholder.empty()
46
  st.warning("⚠️ You did not consent. You can still use the app, but your logs will not be stored.")
47
 
 
 
 
 
 
 
 
 
 
 
 
48
  # -----------------------------
49
  # Parser Function
50
  # -----------------------------
@@ -82,39 +93,17 @@ if uploaded_file:
82
  data = json.load(uploaded_file)
83
  if isinstance(data, dict) and "conversations" in data:
84
  df = parse_chatgpt_export(data)
85
- convo_titles = df["title"].unique()
86
  else:
87
  st.error("Unsupported JSON structure")
88
  st.stop()
89
 
90
  # -----------------------------
91
- # Session State for Pagination
92
- # -----------------------------
93
- if "convo_index" not in st.session_state:
94
- st.session_state.convo_index = 0
95
-
96
- # -----------------------------
97
- # Dropdown Selection
98
  # -----------------------------
99
- selected_title = st.selectbox("Select Conversation", options=convo_titles, index=st.session_state.convo_index)
100
- st.session_state.convo_index = list(convo_titles).index(selected_title)
 
101
 
102
- # -----------------------------
103
- # Pagination Buttons
104
- # -----------------------------
105
- col1, col2, col3 = st.columns([1,2,1])
106
- with col1:
107
- if st.button("β¬… Previous") and st.session_state.convo_index > 0:
108
- st.session_state.convo_index -= 1
109
- selected_title = convo_titles[st.session_state.convo_index]
110
- with col3:
111
- if st.button("Next ➑") and st.session_state.convo_index < len(convo_titles)-1:
112
- st.session_state.convo_index += 1
113
- selected_title = convo_titles[st.session_state.convo_index]
114
-
115
- # -----------------------------
116
- # Filter Selected Conversation
117
- # -----------------------------
118
  convo_df = df[df["title"] == selected_title].copy()
119
 
120
  # -----------------------------
@@ -127,9 +116,23 @@ if uploaded_file:
127
  convo_df["sentiment"] = convo_df["content"].apply(lambda x: analyzer.polarity_scores(str(x))["compound"])
128
 
129
  # -----------------------------
130
- # Show Conversation
131
  # -----------------------------
132
- st.subheader(f"πŸ’¬ Conversation ({st.session_state.convo_index+1}/{len(convo_titles)}): {selected_title}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  st.dataframe(convo_df[["role", "redacted", "sentiment", "create_time"]])
134
 
135
  # -----------------------------
@@ -146,4 +149,4 @@ if uploaded_file:
146
  "messages": convo_df.to_dict(orient="records")
147
  }
148
  collection.insert_one(record)
149
- st.success(f"βœ… Conversation '{selected_title}' saved to MongoDB.")
 
9
  from uuid import uuid4
10
 
11
  # -----------------------------
12
+ # Page Config & Consent
13
  # -----------------------------
14
  st.set_page_config(page_title="ChatGPT Log Analyzer", page_icon="πŸ€–")
15
 
16
+ # Consent
17
  if "consent" not in st.session_state:
18
  st.session_state.consent = ""
19
 
 
41
  st.session_state.id = datetime.now().strftime('%Y%m-%d%H-%M-') + str(uuid4())
42
  st.success("βœ… You consented to participate.")
43
  st.info(f"Your anonymized ID is: **{st.session_state.id}**. Keep this if you want your data deleted later.")
 
44
  elif st.session_state.consent == "No, I do not consent":
45
  placeholder.empty()
46
  st.warning("⚠️ You did not consent. You can still use the app, but your logs will not be stored.")
47
 
48
+ # -----------------------------
49
+ # Privacy Policy Dropdown
50
+ # -----------------------------
51
+ with st.expander("Privacy Policy", expanded=False):
52
+ st.markdown("""
53
+ **Data Collection:** Only ChatGPT logs you upload will be analyzed.
54
+ **PII Redaction:** All detected names, emails, and other personal info will be redacted.
55
+ **Storage:** Data is stored anonymized in our research database.
56
+ **Deletion:** You can request deletion using your anonymized ID.
57
+ """)
58
+
59
  # -----------------------------
60
  # Parser Function
61
  # -----------------------------
 
93
  data = json.load(uploaded_file)
94
  if isinstance(data, dict) and "conversations" in data:
95
  df = parse_chatgpt_export(data)
 
96
  else:
97
  st.error("Unsupported JSON structure")
98
  st.stop()
99
 
100
  # -----------------------------
101
+ # Conversation Selector
 
 
 
 
 
 
102
  # -----------------------------
103
+ st.subheader("πŸ—‚ Select a Conversation")
104
+ convo_titles = df["title"].unique()
105
+ selected_title = st.selectbox("Choose conversation", convo_titles)
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  convo_df = df[df["title"] == selected_title].copy()
108
 
109
  # -----------------------------
 
116
  convo_df["sentiment"] = convo_df["content"].apply(lambda x: analyzer.polarity_scores(str(x))["compound"])
117
 
118
  # -----------------------------
119
+ # Inline PII Editing
120
  # -----------------------------
121
+ st.subheader(f"πŸ’¬ Conversation: {selected_title}")
122
+ editable_rows = []
123
+ for i, row in convo_df.iterrows():
124
+ st.markdown(f"**{row['role'].capitalize()} ({row['create_time']}):**")
125
+ edited_text = st.text_area(
126
+ f"Message {i}",
127
+ value=row["redacted"],
128
+ key=f"edit_{i}"
129
+ )
130
+ editable_rows.append({
131
+ **row,
132
+ "redacted": edited_text
133
+ })
134
+
135
+ convo_df = pd.DataFrame(editable_rows)
136
  st.dataframe(convo_df[["role", "redacted", "sentiment", "create_time"]])
137
 
138
  # -----------------------------
 
149
  "messages": convo_df.to_dict(orient="records")
150
  }
151
  collection.insert_one(record)
152
+ st.success(f"βœ… Conversation '{selected_title}' saved to MongoDB.")