Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +118 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import nltk
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from nltk.corpus import stopwords
|
| 5 |
+
from nltk.tokenize import word_tokenize
|
| 6 |
+
from nltk.stem import WordNetLemmatizer
|
| 7 |
+
from ast import literal_eval
|
| 8 |
+
from nltk.stem import SnowballStemmer
|
| 9 |
+
import warnings
|
| 10 |
+
import streamlit as st
|
| 11 |
+
|
| 12 |
+
warnings.filterwarnings('ignore')
|
| 13 |
+
|
| 14 |
+
# Load your dataset
|
| 15 |
+
df = pd.read_csv('edited_hotel_list.csv')
|
| 16 |
+
|
| 17 |
+
# Function for hotel recommendation
|
| 18 |
+
def recommend_hotel(location, description):
|
| 19 |
+
description = description.lower()
|
| 20 |
+
location = location.lower()
|
| 21 |
+
|
| 22 |
+
word_tokenize(description)
|
| 23 |
+
stop_words = stopwords.words('english')
|
| 24 |
+
lemma = WordNetLemmatizer()
|
| 25 |
+
|
| 26 |
+
# Clean up description text
|
| 27 |
+
filtered_description = {word for word in description.split() if word not in stop_words}
|
| 28 |
+
filtered_description_set = {lemma.lemmatize(word) for word in filtered_description}
|
| 29 |
+
|
| 30 |
+
# Filter the data by location
|
| 31 |
+
country = df[df['country'] == location]
|
| 32 |
+
country = country.set_index(np.arange(country.shape[0]))
|
| 33 |
+
|
| 34 |
+
# Calculate similarity scores
|
| 35 |
+
cos = []
|
| 36 |
+
for i in range(country.shape[0]):
|
| 37 |
+
temp_tokens = set(word_tokenize(country['Tags'][i]))
|
| 38 |
+
vector = temp_tokens.intersection(filtered_description_set)
|
| 39 |
+
cos.append(len(vector))
|
| 40 |
+
|
| 41 |
+
country['similarity'] = cos
|
| 42 |
+
country.sort_values(by=['similarity', 'Average_Score'], ascending=False, inplace=True)
|
| 43 |
+
country.drop_duplicates(subset='Hotel_Name', keep='first', inplace=True)
|
| 44 |
+
country.reset_index(inplace=True)
|
| 45 |
+
|
| 46 |
+
return country[['Hotel_Name', 'Average_Score', 'Hotel_Address']].head(20)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# Streamlit UI: Make the interface fancier and more visually appealing
|
| 50 |
+
def main():
|
| 51 |
+
# Title and description with icons
|
| 52 |
+
st.title('Hotel Recommendation System π¨β¨')
|
| 53 |
+
st.markdown("""
|
| 54 |
+
<style>
|
| 55 |
+
.title {
|
| 56 |
+
font-size: 36px;
|
| 57 |
+
color: #1E90FF;
|
| 58 |
+
font-weight: bold;
|
| 59 |
+
}
|
| 60 |
+
.description {
|
| 61 |
+
font-size: 18px;
|
| 62 |
+
color: #333;
|
| 63 |
+
margin-bottom: 30px;
|
| 64 |
+
}
|
| 65 |
+
.sidebar .sidebar-content {
|
| 66 |
+
background-color: #f7f7f7;
|
| 67 |
+
}
|
| 68 |
+
.footer {
|
| 69 |
+
text-align: center;
|
| 70 |
+
font-size: 14px;
|
| 71 |
+
color: #aaa;
|
| 72 |
+
}
|
| 73 |
+
.recommend-button {
|
| 74 |
+
background-color: #1E90FF;
|
| 75 |
+
color: white;
|
| 76 |
+
padding: 10px;
|
| 77 |
+
border-radius: 5px;
|
| 78 |
+
font-weight: bold;
|
| 79 |
+
}
|
| 80 |
+
</style>
|
| 81 |
+
""", unsafe_allow_html=True)
|
| 82 |
+
|
| 83 |
+
st.markdown('<p class="title">Find Your Perfect Hotel</p>', unsafe_allow_html=True)
|
| 84 |
+
st.markdown('<p class="description">Enter your desired hotel qualifications, and let us recommend the best hotels for you!</p>', unsafe_allow_html=True)
|
| 85 |
+
|
| 86 |
+
# Sidebar for selecting country and entering description
|
| 87 |
+
st.sidebar.header('Your Preferences π‘')
|
| 88 |
+
location = st.sidebar.selectbox('Select Country π', df['country'].unique())
|
| 89 |
+
description = st.sidebar.text_input('Describe your desired hotel features π¨')
|
| 90 |
+
|
| 91 |
+
# Button to trigger recommendation
|
| 92 |
+
if st.sidebar.button('Recommend Hotels π', key="recommend_button"):
|
| 93 |
+
if description:
|
| 94 |
+
hotels = recommend_hotel(location, description)
|
| 95 |
+
st.markdown(f"### Top 20 Recommended Hotels in {location.capitalize()} π")
|
| 96 |
+
|
| 97 |
+
# Fancy dataframe with color-coding and custom styling
|
| 98 |
+
st.dataframe(
|
| 99 |
+
hotels.style.applymap(lambda v: 'background-color: lightblue', subset=['Hotel_Name'])
|
| 100 |
+
.set_properties(**{'text-align': 'center'})
|
| 101 |
+
.set_table_styles([
|
| 102 |
+
{'selector': 'thead th', 'props': [('background-color', '#1E90FF'), ('color', 'white'), ('font-size', '14px')]},
|
| 103 |
+
{'selector': 'tbody td', 'props': [('font-size', '14px')]},
|
| 104 |
+
])
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
else:
|
| 108 |
+
st.warning('Please enter a description of your desired hotel features!')
|
| 109 |
+
|
| 110 |
+
# Footer section with custom styling
|
| 111 |
+
st.markdown("""
|
| 112 |
+
<div class="footer">
|
| 113 |
+
Made with β€οΈ by Senasu
|
| 114 |
+
</div>
|
| 115 |
+
""", unsafe_allow_html=True)
|
| 116 |
+
|
| 117 |
+
if __name__ == '__main__':
|
| 118 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nltk
|
| 2 |
+
streamlit
|