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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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!")
|
|
|
|
| 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 = ""
|
| 389 |
+
st.session_state.df = init_df
|
| 390 |
+
st.session_state.precalculated_df = pd.DataFrame()
|
| 391 |
+
|
| 392 |
+
# #TODO: implement price range as a sliding bar
|
| 393 |
+
# When the user presses "New search", erase everything
|
| 394 |
+
# Propose URLs
|
| 395 |
+
# Show keywords instead of whole strings
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
# Define custom CSS styles for the orange and blue rectangles
|
| 399 |
+
css = """
|
| 400 |
+
<style>
|
| 401 |
+
.orange-box {
|
| 402 |
+
background-color: orange;
|
| 403 |
+
border: 2px solid darkred;
|
| 404 |
+
border-radius: 10px;
|
| 405 |
+
display: inline-block;
|
| 406 |
+
padding: 5px 10px;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
.blue-box {
|
| 410 |
+
background-color: lightblue;
|
| 411 |
+
border: 2px solid navy;
|
| 412 |
+
border-radius: 10px;
|
| 413 |
+
display: inline-block;
|
| 414 |
+
padding: 5px 10px;
|
| 415 |
+
}
|
| 416 |
+
</style>
|
| 417 |
+
"""
|
| 418 |
+
|
| 419 |
+
# options_disability_1 = st.multiselect(
|
| 420 |
+
# 'Do you need a wheelchair?',
|
| 421 |
+
# ['Yes', 'No'], ['No'], key=101)
|
| 422 |
+
|
| 423 |
+
# if options_disability_1 == 'Yes':
|
| 424 |
+
# st.session_state.restrictions.append('Wheelchair')
|
| 425 |
+
|
| 426 |
+
# price_1 = st.select_slider("Your preferred price range", options=('$', '$$', '$$$', '$$$$'), key=3)
|
| 427 |
+
|
| 428 |
+
# st.session_state.preferences_1.append(ambiance_1)
|
| 429 |
+
|
| 430 |
+
# Komplettes Beispiel für die Verwendung der 'with'-Notation
|
| 431 |
+
# with st.form('my_form_1'):
|
| 432 |
+
# st.subheader('**User 1**')
|
| 433 |
+
|
| 434 |
+
st.write("User 1")
|
| 435 |
+
# Eingabe-Widgets
|
| 436 |
+
food_1 = st.selectbox('Select the food type you prefer', st.session_state.food, key=1)
|
| 437 |
+
if food_1 == 'Other':
|
| 438 |
+
food_1 = st.text_input(label="Your description", placeholder="What kind of food would you like to eat?", key=10)
|
| 439 |
+
|
| 440 |
+
ambiance_1 = st.selectbox('What describes your occasion the best?', st.session_state.ambiance, key=2)
|
| 441 |
+
if ambiance_1 == 'Other':
|
| 442 |
+
ambiance_1 = st.text_input(label="Your description", placeholder="How would you describe your meeting?", key=11)
|
| 443 |
+
|
| 444 |
+
options_food_1 = st.multiselect(
|
| 445 |
+
'Do you have any dietary restrictions?',
|
| 446 |
+
['Vegan', 'Vegetarian', 'Halal'], key=100)
|
| 447 |
+
|
| 448 |
+
additional_1 = st.text_input(label="Your description", placeholder="Anything else you wanna share?", key=102)
|
| 449 |
+
|
| 450 |
+
with_kids = st.checkbox('I will come with kids', key=200)
|
| 451 |
+
|
| 452 |
+
# st.subheader('**User 2**')
|
| 453 |
+
st.write("User 2")
|
| 454 |
+
|
| 455 |
+
# Eingabe-Widgets
|
| 456 |
+
food_2 = st.selectbox('Select the food type you prefer', st.session_state.food, key=3)
|
| 457 |
+
if food_2 == 'Other':
|
| 458 |
+
food_2 = st.text_input(label="Your description", placeholder="What kind of food would you like to eat?", key=4)
|
| 459 |
+
|
| 460 |
+
ambiance_2 = st.selectbox('What describes your occasion the best?', st.session_state.ambiance, key=5)
|
| 461 |
+
if ambiance_2 == 'Other':
|
| 462 |
+
ambiance_2 = st.text_input(label="Your description", placeholder="How would you describe your meeting?", key=6)
|
| 463 |
+
|
| 464 |
+
options_food_2 = st.multiselect(
|
| 465 |
+
'Do you have any dietary restrictions?',
|
| 466 |
+
['Vegan', 'Vegetarian', 'Halal'], key=7)
|
| 467 |
+
|
| 468 |
+
additional_2 = st.text_input(label="Your description", placeholder="Anything else you wanna share?", key=8)
|
| 469 |
+
|
| 470 |
+
with_kids_2 = st.checkbox('I will come with kids', key=201)
|
| 471 |
+
|
| 472 |
+
if len(st.session_state.preferences_1) == 0:
|
| 473 |
+
st.session_state.preferences_1.append(food_1)
|
| 474 |
+
st.session_state.preferences_1.append(ambiance_1)
|
| 475 |
+
st.session_state.restrictions.extend(options_food_1)
|
| 476 |
+
if additional_1:
|
| 477 |
+
st.session_state.preferences_1.append(additional_1)
|
| 478 |
+
if with_kids:
|
| 479 |
+
st.session_state.restrictions.append('kids')
|
| 480 |
+
|
| 481 |
+
if len(st.session_state.preferences_2) == 0:
|
| 482 |
+
st.session_state.preferences_2.append(food_2)
|
| 483 |
+
st.session_state.preferences_2.append(ambiance_2)
|
| 484 |
+
st.session_state.restrictions.extend(options_food_2)
|
| 485 |
+
if additional_2:
|
| 486 |
+
st.session_state.preferences_2.append(additional_2)
|
| 487 |
+
if with_kids_2:
|
| 488 |
+
st.session_state.restrictions.append('kids')
|
| 489 |
+
|
| 490 |
+
submitted = st.button('Submit!')
|
| 491 |
+
|
| 492 |
+
if submitted:
|
| 493 |
+
st.markdown("Thanks, we received your preferences!")
|
| 494 |
+
st.session_state.stop_search = False
|
| 495 |
+
|
| 496 |
+
else:
|
| 497 |
+
st.write('☝️ Describe your preferences!')
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
submit = st.button("Find best matches!", type='primary')
|
| 501 |
+
|
| 502 |
+
if submit or (not st.session_state.precalculated_df.empty):
|
| 503 |
+
with st.spinner("Please wait while we are finding the best solution..."):
|
| 504 |
+
if st.session_state.precalculated_df.empty:
|
| 505 |
+
query = get_combined_preferences(st.session_state.preferences_1, st.session_state.preferences_2)
|
| 506 |
+
st.write("Your query is:", query[0])
|
| 507 |
+
#sort places based on restrictions
|
| 508 |
+
st.session_state.precalculated_df = filter_places(st.session_state.restrictions)
|
| 509 |
+
#sort places by elevating preferrences
|
| 510 |
+
st.session_state.precalculated_df = promote_places(query[1])
|
| 511 |
+
st.session_state.precalculated_df = compute_cos_sim(query[0])
|
| 512 |
+
sort_by = st.selectbox(('Sort by:'), st.session_state.options, key=400,
|
| 513 |
+
index=st.session_state.options.index('Relevancy (default)'))
|
| 514 |
+
if sort_by:
|
| 515 |
+
st.session_state.sort_by = sort_by
|
| 516 |
+
results = generate_results(st.session_state.sort_by)
|
| 517 |
+
k = 10
|
| 518 |
+
st.write(f"Here are the best {k} matches to your preferences:")
|
| 519 |
+
i = 1
|
| 520 |
+
nums = list(range(1, 11))
|
| 521 |
+
words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'one: :zero']
|
| 522 |
+
nums_emojis = dict(zip(nums, words))
|
| 523 |
+
for name, score in results.items():
|
| 524 |
+
|
| 525 |
+
condition = st.session_state.precalculated_df['Names'] == name
|
| 526 |
+
rating = st.session_state.precalculated_df.loc[condition, 'Rating'].values[0]
|
| 527 |
+
st.write(f":{nums_emojis[i]}: **{name}** **({str(rating)}**:star:) :", 'match score:', score)
|
| 528 |
+
|
| 529 |
+
# Use the condition to extract the value(s)
|
| 530 |
+
# description = st.session_state.precalculated_df.loc[condition, 'Strings']
|
| 531 |
+
# st.write(description)
|
| 532 |
+
|
| 533 |
+
type = [item for item in eval(st.session_state.precalculated_df.loc[condition, 'Category'].values[0])]
|
| 534 |
+
# Display HTML with the custom styles
|
| 535 |
+
for word in type:
|
| 536 |
+
st.markdown(css, unsafe_allow_html=True)
|
| 537 |
+
st.markdown(f'<div class="blue-box">{word}</div>', unsafe_allow_html=True)
|
| 538 |
+
# st.write("Restaurant type:", str(type))
|
| 539 |
+
|
| 540 |
+
keywords = [item[0] for item in eval(st.session_state.precalculated_df.loc[condition, 'Keywords'].values[0])]
|
| 541 |
+
for pair in keywords[:3]:
|
| 542 |
+
st.markdown(css, unsafe_allow_html=True)
|
| 543 |
+
st.markdown(f'<div class="orange-box">{pair[0]} {pair[1]}</div>', unsafe_allow_html=True)
|
| 544 |
+
# st.write("Restaurant type:", str(type))
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
url = st.session_state.precalculated_df.loc[condition, 'URL'].values[0]
|
| 548 |
+
st.write("_Check on the map:_", url)
|
| 549 |
+
|
| 550 |
+
# st.markdown("This is a text with <span style='font-size: 20px;'>bigger</span> and <i>italic</i> text.", unsafe_allow_html=True)
|
| 551 |
+
# st.markdown("<span style='font-size: 24px;'>This is larger text</span>", unsafe_allow_html=True)
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
|
| 556 |
stop = st.button("New search!", type='primary', key=500)
|
| 557 |
if stop:
|
| 558 |
st.write("New search is launched. Please specify your preferences in the form!")
|