AI-Naga commited on
Commit
3c24daa
·
1 Parent(s): b10d434

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.metrics.pairwise import cosine_similarity
5
+ from sklearn.feature_extraction.text import CountVectorizer
6
+
7
+ # Dummy data for agents
8
+ agents = pd.DataFrame({
9
+ 'agent_id': range(1, 21),
10
+ 'location_expertise': ['Toronto', 'Vancouver', 'Montreal'] * 6 + ['Toronto', 'Vancouver'],
11
+ 'property_type_expertise': ['Condo', 'House', 'Apartment'] * 6 + ['Condo', 'House'],
12
+ 'average_deal_completion_rate': np.random.random(20),
13
+ 'language': ['English', 'French', 'Hindi', 'English', 'French', 'English', 'Hindi', 'French', 'English', 'Hindi'] * 2,
14
+ 'amenities': ['Pool,Gym', 'Gym,Parking', 'Pool,Parking,Gym', 'Parking', 'Pool,Gym', 'Gym,Parking', 'Pool', 'Gym', 'Parking,Pool', 'Pool'] * 2
15
+ })
16
+
17
+ # Function to calculate cosine similarity
18
+ def calculate_similarity(client_features, agents):
19
+ # Combining client features
20
+ client_combined_features = [client_features['preferred_location'] + " " + client_features['preferred_property_type'] + " " + client_features['language'] + " " + client_features['amenities']]
21
+
22
+ agents['combined_features'] = agents['location_expertise'] + " " + agents['property_type_expertise'] + " " + agents['language'] + " " + agents['amenities']
23
+
24
+ # Count Vectorizer for combined features
25
+ vectorizer = CountVectorizer()
26
+ count_matrix = vectorizer.fit_transform(pd.concat([pd.Series(client_combined_features), agents['combined_features']]))
27
+
28
+ # Calculate cosine similarity
29
+ similarity = cosine_similarity(count_matrix[0:1], count_matrix[1:])
30
+
31
+ # Get top 3 agents
32
+ top_agents_indices = np.argsort(similarity[0])[-3:][::-1]
33
+ top_agents_scores = [similarity[0][i] for i in top_agents_indices]
34
+ top_agents = [agents.iloc[i] for i in top_agents_indices]
35
+ return zip(top_agents_scores, top_agents)
36
+
37
+ # Streamlit app
38
+ st.title("Real Estate Agent Recommender")
39
+
40
+ # Input fields
41
+ preferred_location = st.selectbox("Preferred Location", ['Toronto', 'Vancouver', 'Montreal'])
42
+ preferred_property_type = st.selectbox("Preferred Property Type", ['Condo', 'House', 'Apartment'])
43
+ max_budget = st.slider("Maximum Budget", 100000, 1000000, 300000, 10000)
44
+ language = st.selectbox("Preferred Agent Language", ['English', 'French', 'Hindi'])
45
+ amenities = st.multiselect("Preferred Amenities", ['Pool', 'Gym', 'Parking'])
46
+
47
+ # Button to get recommendations
48
+ if st.button("Get Recommendations"):
49
+ client_features = {
50
+ 'preferred_location': preferred_location,
51
+ 'preferred_property_type': preferred_property_type,
52
+ 'max_budget': max_budget,
53
+ 'language': language,
54
+ 'amenities': ",".join(amenities)
55
+ }
56
+ recommendations = calculate_similarity(client_features, agents)
57
+
58
+ # Create DataFrame for displaying the results in a table
59
+ recommendation_data = []
60
+ rank = 1
61
+ for score, agent in recommendations:
62
+ recommendation_data.append([rank, score, agent['agent_id'], agent['location_expertise'], agent['property_type_expertise'], agent['average_deal_completion_rate'], agent['language'], agent['amenities']])
63
+ rank += 1
64
+ recommendation_df = pd.DataFrame(recommendation_data, columns=['Rank', 'Score', 'Agent ID', 'Location Expertise', 'Property Type Expertise', 'Average Deal Completion Rate', 'Language', 'Amenities'])
65
+ st.table(recommendation_df)