Yara Kyrychenko commited on
Commit
1e27a05
Β·
1 Parent(s): 5b21e9f

remove duplication

Browse files
Files changed (1) hide show
  1. app.py +28 -46
app.py CHANGED
@@ -3,8 +3,6 @@ import requests
3
  from pymongo.mongo_client import MongoClient
4
  from pymongo.server_api import ServerApi
5
  from datetime import datetime
6
- import time
7
- #import webbrowser
8
  import random
9
 
10
  st.set_page_config(
@@ -75,9 +73,9 @@ with st.sidebar:
75
 
76
  ❗ **Do not share any personal information (e.g., name or address).**
77
 
78
- ⚠️ You must click on **at least 5 links** before you can submit the search. An *End Search* button will appear then. You can continue before submitting, but **you must submit the conversation to receive compensation**.
79
 
80
- {"β˜‘" if st.session_state.inserted > 1 else "☐"} **Step 3. Use the *End Search* button to submit your response.**
81
 
82
  **Do not forget to copy & paste your completion code!**
83
 
@@ -120,7 +118,7 @@ def display_results(results):
120
 
121
  @st.dialog('Form', width="large")
122
  def form():
123
- st.markdown("**❗ Please answer every question to proceed.**")
124
  st.session_state.age = st.text_input("How old are you in years?")
125
  st.session_state.gender = st.radio("Do you describe yourself as a man, a woman, or in some other way?",
126
  ['','Man', 'Woman', 'Other'])
@@ -167,50 +165,19 @@ def form():
167
  st.session_state.user_data["inserted"] = st.session_state.inserted
168
  st.session_state.user_data["submission_time"] = datetime.now()
169
 
170
- with MongoClient(st.secrets["mongo"],server_api=ServerApi('1')) as client:
171
- db = client.chat
172
- collection = db.app
173
- user_data = st.session_state.user_data
174
- collection.insert_one(user_data)
175
- st.session_state.inserted += 1
 
176
  st.session_state.submitted = True
177
  st.rerun()
178
 
179
  if st.session_state.gotit and st.session_state.submitted == False:
180
  form()
181
 
182
- @st.dialog('Submit', width="large")
183
- def submit():
184
- st.markdown("You must answer all questions marked with a ❗ to submit.")
185
- if st.query_params["p"] != "n":
186
- st.slider('❗ How would you rate the interaction on a scale from *Terrible* to *Perfect*?', 0, 100, format="", key="score", value=50)
187
- st.slider('❗ How personalized did the interaction feel, on a scale from *Not at all* to *Extremely personalized*?', 0, 100, format="", key="personalization_score", value=50)
188
- st.slider('❗ How much do you feel you learned from this interaction, on a scale from *Nothing* to *Very much*?', 0, 100, format="", key="knowledge_score", value=50)
189
- else:
190
- st.session_state.score = 0
191
- st.session_state.personalization_score = 0
192
- st.session_state.knowledge_score = 0
193
-
194
- st.text_area('Any feedback?',key="feedback")
195
- if st.button('Submit', key=None, help=None, use_container_width=True, disabled=st.session_state.score==50 or st.session_state.personalization_score==50):
196
- keys = ["score", "personalization_score", "knowledge_score",
197
- "feedback",
198
- "inserted", "messages", "convo_start_time", 'clicked_links']
199
-
200
- st.session_state.user_data.update({key: st.session_state[key] for key in keys})
201
-
202
- st.session_state.user_data["convo_end_time"] = datetime.now()
203
-
204
- with MongoClient(st.secrets["mongo"],server_api=ServerApi('1')) as client:
205
- db = client.chat
206
- collection = db.app
207
- user_data = st.session_state.user_data
208
- del user_data['_id']
209
-
210
- collection.insert_one(user_data)
211
- st.session_state.inserted += 1
212
-
213
- st.rerun()
214
 
215
  if len(st.session_state.messages) >= st.session_state.max_messages:
216
  st.info(
@@ -226,7 +193,7 @@ elif st.session_state.inserted > 1:
226
  st.markdown(f'## {st.session_state.user_id}')
227
  st.markdown('**Please copy the code and enter it into the survey field below.**')
228
 
229
- elif query := st.text_input("Enter search query and press Enter ⏎", placeholder="Search Google..."):
230
 
231
  if query != st.session_state.messages[-1]["query"] or st.session_state.page != st.session_state.messages[-1]["page"]:
232
  results = google_search(query, st.session_state.page)
@@ -250,6 +217,21 @@ elif query := st.text_input("Enter search query and press Enter ⏎", placeholde
250
  if (len(st.session_state.clicked_links) > 4 or st.session_state.max_messages == len(st.session_state.messages)) and not st.session_state.inserted > 1:
251
  columns = st.columns((1,1,1))
252
  with columns[2]:
253
- if st.button("End Search",use_container_width=True):
254
- submit()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
 
 
3
  from pymongo.mongo_client import MongoClient
4
  from pymongo.server_api import ServerApi
5
  from datetime import datetime
 
 
6
  import random
7
 
8
  st.set_page_config(
 
73
 
74
  ❗ **Do not share any personal information (e.g., name or address).**
75
 
76
+ ⚠️ You must click on **at least 5 links** before you can submit the search. A *Finish* button will appear then. You can continue before submitting, but **you must finish and enter your completion code into the survey to recieve compensation**.
77
 
78
+ {"β˜‘" if st.session_state.inserted > 1 else "☐"} **Step 3. Use the *Finish* button to submit your response.**
79
 
80
  **Do not forget to copy & paste your completion code!**
81
 
 
118
 
119
  @st.dialog('Form', width="large")
120
  def form():
121
+ st.markdown("**Please answer every question to proceed.**")
122
  st.session_state.age = st.text_input("How old are you in years?")
123
  st.session_state.gender = st.radio("Do you describe yourself as a man, a woman, or in some other way?",
124
  ['','Man', 'Woman', 'Other'])
 
165
  st.session_state.user_data["inserted"] = st.session_state.inserted
166
  st.session_state.user_data["submission_time"] = datetime.now()
167
 
168
+ #with MongoClient(st.secrets["mongo"],server_api=ServerApi('1')) as client:
169
+ #db = client.chat
170
+ #collection = db.app
171
+ #user_data = st.session_state.user_data
172
+ #collection.insert_one(user_data)
173
+
174
+ st.session_state.inserted += 1
175
  st.session_state.submitted = True
176
  st.rerun()
177
 
178
  if st.session_state.gotit and st.session_state.submitted == False:
179
  form()
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  if len(st.session_state.messages) >= st.session_state.max_messages:
183
  st.info(
 
193
  st.markdown(f'## {st.session_state.user_id}')
194
  st.markdown('**Please copy the code and enter it into the survey field below.**')
195
 
196
+ elif query := st.text_input("Enter search query and press Enter", placeholder="Search Google..."):
197
 
198
  if query != st.session_state.messages[-1]["query"] or st.session_state.page != st.session_state.messages[-1]["page"]:
199
  results = google_search(query, st.session_state.page)
 
217
  if (len(st.session_state.clicked_links) > 4 or st.session_state.max_messages == len(st.session_state.messages)) and not st.session_state.inserted > 1:
218
  columns = st.columns((1,1,1))
219
  with columns[2]:
220
+ if st.button("Finish",use_container_width=True):
221
+ keys = ["inserted", "messages", "convo_start_time", 'clicked_links']
222
+
223
+ st.session_state.user_data.update({key: st.session_state[key] for key in keys})
224
+
225
+ st.session_state.user_data["convo_end_time"] = datetime.now()
226
+
227
+ with MongoClient(st.secrets["mongo"],server_api=ServerApi('1')) as client:
228
+ db = client.chat
229
+ collection = db.app
230
+ user_data = st.session_state.user_data
231
+ #del user_data['_id']
232
+
233
+ collection.insert_one(user_data)
234
+ st.session_state.inserted += 1
235
+
236
+ st.rerun()
237