Manith Marapperuma 👾
commited on
Commit
·
87af1bc
1
Parent(s):
5ec9915
init commit
Browse files- app.py +48 -0
- recommendation_model.pkl +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
|
4 |
+
def load_model(filename):
|
5 |
+
with open(filename, 'rb') as f:
|
6 |
+
return pickle.load(f)
|
7 |
+
|
8 |
+
# Load the model
|
9 |
+
loaded_model = load_model('recommendation_model.pkl')
|
10 |
+
|
11 |
+
def get_recommendations(input_categories):
|
12 |
+
tfidf_vectorizer = loaded_model['tfidf_vectorizer']
|
13 |
+
knn_classifier = loaded_model['knn_classifier']
|
14 |
+
df = loaded_model['df']
|
15 |
+
|
16 |
+
all_predictions = []
|
17 |
+
|
18 |
+
for category in input_categories:
|
19 |
+
category_tfidf = tfidf_vectorizer.transform([category])
|
20 |
+
top_20_indices = knn_classifier.kneighbors(category_tfidf, n_neighbors=20, return_distance=False)[0]
|
21 |
+
top_20_places = df.iloc[top_20_indices]
|
22 |
+
best_2_places = top_20_places.sort_values('normalized_score', ascending=False).head(2)
|
23 |
+
|
24 |
+
all_predictions.append({
|
25 |
+
'category': category,
|
26 |
+
'predictions': best_2_places[['name', 'rating', 'user_ratings_total', 'normalized_score']].to_dict('records')
|
27 |
+
})
|
28 |
+
|
29 |
+
return all_predictions
|
30 |
+
|
31 |
+
# Streamlit app
|
32 |
+
st.title("Place Recommendation System")
|
33 |
+
|
34 |
+
st.write("Enter the categories you are interested in (comma-separated):")
|
35 |
+
input_categories = st.text_input("Categories", "historical monuments, history tours, wildlife")
|
36 |
+
|
37 |
+
if st.button("Get Recommendations"):
|
38 |
+
categories_list = [category.strip() for category in input_categories.split(',')]
|
39 |
+
recommendations = get_recommendations(categories_list)
|
40 |
+
|
41 |
+
for prediction in recommendations:
|
42 |
+
st.subheader(f"Top 2 recommended places for '{prediction['category']}':")
|
43 |
+
for place in prediction['predictions']:
|
44 |
+
st.write(f"**Name:** {place['name']}")
|
45 |
+
st.write(f"**Rating:** {place['rating']:.2f}")
|
46 |
+
st.write(f"**Review Count:** {place['user_ratings_total']}")
|
47 |
+
st.write(f"**Score:** {place['normalized_score']:.4f}")
|
48 |
+
st.write("") # Add a blank line for better spacing
|
recommendation_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4c7cdc3d1a96ec36fc44eb3b0c863e07ff11df95364e302f43710c289d76ee40
|
3 |
+
size 447420
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pickle
|