Intention commited on
Commit
1310ca1
Β·
1 Parent(s): 4ff90c7

add sidebar

Browse files
Files changed (1) hide show
  1. app.py +29 -42
app.py CHANGED
@@ -9,52 +9,49 @@ from datetime import datetime
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
 
20
- placeholder = st.empty()
21
- with placeholder.container():
22
- with st.expander("Consent", expanded=True):
23
- st.markdown("##### Take Part in Our Study")
24
- st.markdown("""
25
- Please consider participating in our research study on ChatGPT interactions.
26
- In this study, you will be asked to upload ChatGPT logs. These will be analyzed for sentiment, redacted to remove personal information, and stored in a research database.
27
-
28
- **You must be 18 years or older to participate.**
29
- You can still use the app without sharing your data by clicking **'No, I do not consent'**.
30
- """)
31
-
32
- st.radio(
33
- "**Do you consent to participating in this study and sharing anonymized information?**",
34
- ["", "Yes, I consent", "No, I do not consent"],
35
- key="consent", horizontal=True
36
- )
37
 
 
 
 
 
 
 
 
 
 
 
 
38
  if st.session_state.consent == "Yes, I consent":
39
- placeholder.empty()
40
  if "id" not in st.session_state:
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
- try:
53
- with open("PrivacyPolicy.md", "r") as f:
54
- st.markdown(f.read())
55
- except FileNotFoundError:
56
- st.error("Privacy policy file not found. Please add `privacy_policy.md` to the project.")
57
-
58
  # -----------------------------
59
  # Parser Function
60
  # -----------------------------
@@ -84,10 +81,8 @@ def parse_chatgpt_export(data):
84
  return pd.DataFrame(rows)
85
 
86
  # -----------------------------
87
- # File Upload
88
  # -----------------------------
89
- uploaded_file = st.file_uploader("Upload ChatGPT export (.json)", type=["json"])
90
-
91
  if uploaded_file:
92
  data = json.load(uploaded_file)
93
  if isinstance(data, dict) and "conversations" in data:
@@ -96,18 +91,14 @@ if uploaded_file:
96
  st.error("Unsupported JSON structure")
97
  st.stop()
98
 
99
- # -----------------------------
100
  # Conversation Selector
101
- # -----------------------------
102
  st.subheader("πŸ—‚ Select a Conversation")
103
  convo_titles = df["title"].unique()
104
  selected_title = st.selectbox("Choose conversation", convo_titles)
105
 
106
  convo_df = df[df["title"] == selected_title].copy()
107
 
108
- # -----------------------------
109
  # Scrub + Sentiment
110
- # -----------------------------
111
  cleaner = scrubadub.Scrubber()
112
  analyzer = SentimentIntensityAnalyzer()
113
 
@@ -124,9 +115,7 @@ if uploaded_file:
124
 
125
  convo_df = pd.DataFrame(redacted_rows)
126
 
127
- # -----------------------------
128
  # Inline PII Editing
129
- # -----------------------------
130
  st.subheader(f"πŸ’¬ Conversation: {selected_title}")
131
  edited_rows = []
132
  for i, row in convo_df.iterrows():
@@ -144,9 +133,7 @@ if uploaded_file:
144
  convo_df = pd.DataFrame(edited_rows)
145
  st.dataframe(convo_df[["role", "redacted", "sentiment", "create_time"]])
146
 
147
- # -----------------------------
148
- # Optional: Save to MongoDB
149
- # -----------------------------
150
  if st.button("πŸ“₯ Save Conversation to Database"):
151
  with MongoClient(st.secrets["mongo"], server_api=ServerApi('1')) as client:
152
  db = client.bridge
 
9
  from uuid import uuid4
10
 
11
  # -----------------------------
12
+ # Page Config
13
  # -----------------------------
14
  st.set_page_config(page_title="ChatGPT Log Analyzer", page_icon="πŸ€–")
15
 
16
+ # -----------------------------
17
+ # Sidebar: App Navigation & File Upload
18
+ # -----------------------------
19
+ st.sidebar.title("βš™οΈ Settings")
20
+
21
  # Consent
22
  if "consent" not in st.session_state:
23
  st.session_state.consent = ""
24
 
25
+ with st.sidebar.expander("Consent Form", expanded=True):
26
+ st.radio(
27
+ "**Do you consent to participating in this study?**",
28
+ ["", "Yes, I consent", "No, I do not consent"],
29
+ key="consent"
30
+ )
31
+
32
+ # File Upload
33
+ uploaded_file = st.sidebar.file_uploader("πŸ“‚ Upload ChatGPT export (.json)", type=["json"])
 
 
 
 
 
 
 
 
34
 
35
+ # Privacy Policy in Sidebar
36
+ with st.sidebar.expander("Privacy Policy", expanded=False):
37
+ try:
38
+ with open("PrivacyPolicy.md", "r") as f:
39
+ st.markdown(f.read())
40
+ except FileNotFoundError:
41
+ st.error("Privacy policy file not found. Please add `privacy_policy.md`.")
42
+
43
+ # -----------------------------
44
+ # Consent Messages in Main Page
45
+ # -----------------------------
46
  if st.session_state.consent == "Yes, I consent":
 
47
  if "id" not in st.session_state:
48
  st.session_state.id = datetime.now().strftime('%Y%m-%d%H-%M-') + str(uuid4())
49
  st.success("βœ… You consented to participate.")
50
  st.info(f"Your anonymized ID is: **{st.session_state.id}**. Keep this if you want your data deleted later.")
51
+
52
  elif st.session_state.consent == "No, I do not consent":
 
53
  st.warning("⚠️ You did not consent. You can still use the app, but your logs will not be stored.")
54
 
 
 
 
 
 
 
 
 
 
 
55
  # -----------------------------
56
  # Parser Function
57
  # -----------------------------
 
81
  return pd.DataFrame(rows)
82
 
83
  # -----------------------------
84
+ # Main Content (only if file uploaded)
85
  # -----------------------------
 
 
86
  if uploaded_file:
87
  data = json.load(uploaded_file)
88
  if isinstance(data, dict) and "conversations" in data:
 
91
  st.error("Unsupported JSON structure")
92
  st.stop()
93
 
 
94
  # Conversation Selector
 
95
  st.subheader("πŸ—‚ Select a Conversation")
96
  convo_titles = df["title"].unique()
97
  selected_title = st.selectbox("Choose conversation", convo_titles)
98
 
99
  convo_df = df[df["title"] == selected_title].copy()
100
 
 
101
  # Scrub + Sentiment
 
102
  cleaner = scrubadub.Scrubber()
103
  analyzer = SentimentIntensityAnalyzer()
104
 
 
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():
 
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