Yara Kyrychenko commited on
Commit
5b21e9f
Β·
1 Parent(s): fdac732
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -4,7 +4,7 @@ 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(
@@ -90,7 +90,7 @@ with st.sidebar:
90
 
91
  @st.cache_data
92
  def google_search(query, page):
93
- start_index = (page - 1) * RESULTS_PER_PAGE + 1 # Google API uses 1-based index
94
  url = f"https://www.googleapis.com/customsearch/v1?q={query}&key={st.secrets['GOOGLE_API_KEY']}&cx={st.secrets['GOOGLE_CX']}&start={start_index}"
95
  response = requests.get(url)
96
  return response.json()
@@ -109,12 +109,10 @@ def display_results(results):
109
  st.image(image_url, width=160)
110
 
111
  with col2:
112
- #st.markdown(f"**{item['title']}**")
113
- #st.markdown(item['snippet'])
114
-
115
  if st.button(f"πŸ”— **{item['title']}**", item['link'], type='tertiary'):
116
- st.session_state.clicked_links.append(item['link'])
117
- webbrowser.open(item['link'])
 
118
  st.markdown(item['snippet'])
119
 
120
 
@@ -185,9 +183,9 @@ if st.session_state.gotit and st.session_state.submitted == False:
185
  def submit():
186
  st.markdown("You must answer all questions marked with a ❗ to submit.")
187
  if st.query_params["p"] != "n":
188
- st.slider('❗ How would you rate the conversation on a scale from *Terrible* to *Perfect*?', 0, 100, format="", key="score", value=50)
189
- st.slider('❗ How personalized did the conversation feel, on a scale from *Not at all* to *Extremely personalized*?', 0, 100, format="", key="personalization_score", value=50)
190
- st.slider('❗ How knowledgeable do you feel the chatbot was, on a scale from *Not at all* to *Extremely knowledgeable*?', 0, 100, format="", key="knowledge_score", value=50)
191
  else:
192
  st.session_state.score = 0
193
  st.session_state.personalization_score = 0
@@ -238,13 +236,13 @@ elif query := st.text_input("Enter search query and press Enter ⏎", placeholde
238
 
239
  col1, _, col2 = st.columns([.2, .6, .2])
240
  with col1:
241
- if st.session_state.page > 1: # Show "Previous" button only if not on first page
242
  if st.button("⬅️ Previous Page",use_container_width=True):
243
  st.session_state.page -= 1
244
  st.rerun()
245
 
246
  with col2:
247
- if "nextPage" in st.session_state.messages[-1]["results"].get("queries", {}): # Check if next page exists
248
  if st.button("Next Page ➑️",use_container_width=True):
249
  st.session_state.page += 1
250
  st.rerun()
 
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(
 
90
 
91
  @st.cache_data
92
  def google_search(query, page):
93
+ start_index = (page - 1) * RESULTS_PER_PAGE + 1
94
  url = f"https://www.googleapis.com/customsearch/v1?q={query}&key={st.secrets['GOOGLE_API_KEY']}&cx={st.secrets['GOOGLE_CX']}&start={start_index}"
95
  response = requests.get(url)
96
  return response.json()
 
109
  st.image(image_url, width=160)
110
 
111
  with col2:
 
 
 
112
  if st.button(f"πŸ”— **{item['title']}**", item['link'], type='tertiary'):
113
+ st.session_state.clicked_links.append({"link": item['link'], "time": datetime.now()})
114
+ #webbrowser.open(item['link'])
115
+ st.markdown(f"[Click to view: {item['link']}]({item['link']})")
116
  st.markdown(item['snippet'])
117
 
118
 
 
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
 
236
 
237
  col1, _, col2 = st.columns([.2, .6, .2])
238
  with col1:
239
+ if st.session_state.page > 1:
240
  if st.button("⬅️ Previous Page",use_container_width=True):
241
  st.session_state.page -= 1
242
  st.rerun()
243
 
244
  with col2:
245
+ if "nextPage" in st.session_state.messages[-1]["results"].get("queries", {}):
246
  if st.button("Next Page ➑️",use_container_width=True):
247
  st.session_state.page += 1
248
  st.rerun()