Spaces:
Sleeping
Sleeping
Added design to the outputs
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ def str_to_numpy(array_string):
|
|
| 29 |
|
| 30 |
@st.cache_data # 👈 Add the caching decorator
|
| 31 |
def load_data():
|
| 32 |
-
vectors_df = pd.read_csv('restaurants_dataframe_with_embeddings.csv')
|
| 33 |
embeds = dict(enumerate(vectors_df['Embeddings']))
|
| 34 |
rest_names = list(vectors_df['Names'])
|
| 35 |
vectors_df['Weights'] = [1]*len(vectors_df)
|
|
@@ -40,18 +40,6 @@ restaurants_embeds, rest_names, init_df = load_data()
|
|
| 40 |
|
| 41 |
model, tokenizer = get_models()
|
| 42 |
|
| 43 |
-
# query_params = st.experimental_get_query_params()
|
| 44 |
-
# st.write("query_params")
|
| 45 |
-
# st.write(query_params)
|
| 46 |
-
|
| 47 |
-
# def update_params():
|
| 48 |
-
# st.experimental_set_query_params(
|
| 49 |
-
# sorting=st.session_state.sort_by)
|
| 50 |
-
|
| 51 |
-
# if query_params:
|
| 52 |
-
# sort_by = query_params["sorting"][0]
|
| 53 |
-
# st.session_state.sort_by = sort_by
|
| 54 |
-
|
| 55 |
#a function that takes a sentence and converts it into embeddings
|
| 56 |
def get_bert_embeddings(sentence, model, tokenizer):
|
| 57 |
inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True)
|
|
@@ -233,6 +221,28 @@ st.title("GoTogether!")
|
|
| 233 |
st.markdown("Tell us about your preferences!")
|
| 234 |
st.caption("In section 'Others', you can describe any wishes.")
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
# options_disability_1 = st.multiselect(
|
| 237 |
# 'Do you need a wheelchair?',
|
| 238 |
# ['Yes', 'No'], ['No'], key=101)
|
|
@@ -280,7 +290,7 @@ if ambiance_2 == 'Other':
|
|
| 280 |
|
| 281 |
options_food_2 = st.multiselect(
|
| 282 |
'Do you have any dietary restrictions?',
|
| 283 |
-
['Vegan', 'Vegetarian', 'Halal'
|
| 284 |
|
| 285 |
additional_2 = st.text_input(label="Your description", placeholder="Anything else you wanna share?", key=8)
|
| 286 |
|
|
@@ -334,18 +344,45 @@ if submit or (not st.session_state.precalculated_df.empty):
|
|
| 334 |
k = 10
|
| 335 |
st.write(f"Here are the best {k} matches to your preferences:")
|
| 336 |
i = 1
|
|
|
|
|
|
|
|
|
|
| 337 |
for name, score in results.items():
|
| 338 |
-
|
| 339 |
condition = st.session_state.precalculated_df['Names'] == name
|
|
|
|
|
|
|
|
|
|
| 340 |
# Use the condition to extract the value(s)
|
| 341 |
-
description = st.session_state.precalculated_df.loc[condition, 'Strings']
|
| 342 |
-
st.write(description)
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
stop = st.button("New search!", type='primary', key=500)
|
| 348 |
if stop:
|
|
|
|
| 349 |
st.session_state.preferences_1, st.session_state.preferences_2 = [], []
|
| 350 |
st.session_state.restrictions = []
|
| 351 |
st.session_state.sort_by = ""
|
|
|
|
| 29 |
|
| 30 |
@st.cache_data # 👈 Add the caching decorator
|
| 31 |
def load_data():
|
| 32 |
+
vectors_df = pd.read_csv('restaurants_dataframe_with_embeddings.csv', encoding="utf-8")
|
| 33 |
embeds = dict(enumerate(vectors_df['Embeddings']))
|
| 34 |
rest_names = list(vectors_df['Names'])
|
| 35 |
vectors_df['Weights'] = [1]*len(vectors_df)
|
|
|
|
| 40 |
|
| 41 |
model, tokenizer = get_models()
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
#a function that takes a sentence and converts it into embeddings
|
| 44 |
def get_bert_embeddings(sentence, model, tokenizer):
|
| 45 |
inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True)
|
|
|
|
| 221 |
st.markdown("Tell us about your preferences!")
|
| 222 |
st.caption("In section 'Others', you can describe any wishes.")
|
| 223 |
|
| 224 |
+
|
| 225 |
+
# Define custom CSS styles for the orange and blue rectangles
|
| 226 |
+
css = """
|
| 227 |
+
<style>
|
| 228 |
+
.orange-box {
|
| 229 |
+
background-color: orange;
|
| 230 |
+
border: 2px solid darkred;
|
| 231 |
+
border-radius: 10px;
|
| 232 |
+
display: inline-block;
|
| 233 |
+
padding: 5px 10px;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
.blue-box {
|
| 237 |
+
background-color: lightblue;
|
| 238 |
+
border: 2px solid navy;
|
| 239 |
+
border-radius: 10px;
|
| 240 |
+
display: inline-block;
|
| 241 |
+
padding: 5px 10px;
|
| 242 |
+
}
|
| 243 |
+
</style>
|
| 244 |
+
"""
|
| 245 |
+
|
| 246 |
# options_disability_1 = st.multiselect(
|
| 247 |
# 'Do you need a wheelchair?',
|
| 248 |
# ['Yes', 'No'], ['No'], key=101)
|
|
|
|
| 290 |
|
| 291 |
options_food_2 = st.multiselect(
|
| 292 |
'Do you have any dietary restrictions?',
|
| 293 |
+
['Vegan', 'Vegetarian', 'Halal'], key=7)
|
| 294 |
|
| 295 |
additional_2 = st.text_input(label="Your description", placeholder="Anything else you wanna share?", key=8)
|
| 296 |
|
|
|
|
| 344 |
k = 10
|
| 345 |
st.write(f"Here are the best {k} matches to your preferences:")
|
| 346 |
i = 1
|
| 347 |
+
nums = list(range(1, 11))
|
| 348 |
+
words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'one: :zero']
|
| 349 |
+
nums_emojis = dict(zip(nums, words))
|
| 350 |
for name, score in results.items():
|
| 351 |
+
|
| 352 |
condition = st.session_state.precalculated_df['Names'] == name
|
| 353 |
+
rating = st.session_state.precalculated_df.loc[condition, 'Rating'].values[0]
|
| 354 |
+
st.write(f":{nums_emojis[i]}: **{name}** **({str(rating)}**:star:) :", 'match score:', score)
|
| 355 |
+
|
| 356 |
# Use the condition to extract the value(s)
|
| 357 |
+
# description = st.session_state.precalculated_df.loc[condition, 'Strings']
|
| 358 |
+
# st.write(description)
|
| 359 |
+
|
| 360 |
+
type = [item for item in eval(st.session_state.precalculated_df.loc[condition, 'Category'].values[0])]
|
| 361 |
+
# Display HTML with the custom styles
|
| 362 |
+
for word in type:
|
| 363 |
+
st.markdown(css, unsafe_allow_html=True)
|
| 364 |
+
st.markdown(f'<div class="blue-box">{word}</div>', unsafe_allow_html=True)
|
| 365 |
+
# st.write("Restaurant type:", str(type))
|
| 366 |
+
|
| 367 |
+
keywords = [item[0] for item in eval(st.session_state.precalculated_df.loc[condition, 'Keywords'].values[0])]
|
| 368 |
+
for pair in keywords[:3]:
|
| 369 |
+
st.markdown(css, unsafe_allow_html=True)
|
| 370 |
+
st.markdown(f'<div class="orange-box">{pair[0]} {pair[1]}</div>', unsafe_allow_html=True)
|
| 371 |
+
# st.write("Restaurant type:", str(type))
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
url = st.session_state.precalculated_df.loc[condition, 'URL'].values[0]
|
| 375 |
+
st.write("_Check on the map:_", url)
|
| 376 |
+
|
| 377 |
+
# st.markdown("This is a text with <span style='font-size: 20px;'>bigger</span> and <i>italic</i> text.", unsafe_allow_html=True)
|
| 378 |
+
# st.markdown("<span style='font-size: 24px;'>This is larger text</span>", unsafe_allow_html=True)
|
| 379 |
+
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
stop = st.button("New search!", type='primary', key=500)
|
| 384 |
if stop:
|
| 385 |
+
st.write("New search is launched. Please specify your preferences in the form!")
|
| 386 |
st.session_state.preferences_1, st.session_state.preferences_2 = [], []
|
| 387 |
st.session_state.restrictions = []
|
| 388 |
st.session_state.sort_by = ""
|