Spaces:
Sleeping
Sleeping
Yara Kyrychenko
commited on
Commit
Β·
5b21e9f
1
Parent(s):
fdac732
links
Browse files
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
|
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
|
189 |
-
st.slider('β How personalized did the
|
190 |
-
st.slider('β How
|
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:
|
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", {}):
|
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()
|