Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ def recommend_laptops(age=None, category=None, gender=None, user_id=None, num_re
|
|
38 |
'Gender': [gender]
|
39 |
})
|
40 |
new_user_data = new_user_data.merge(laptop_df, how='cross')
|
41 |
-
new_user_data['Predicted_Rating'] = new_user_data.apply(lambda row: model.predict(
|
42 |
recommendations = new_user_data.sort_values(by='Predicted_Rating', ascending=False).head(num_recommendations)
|
43 |
|
44 |
return recommendations
|
@@ -62,29 +62,15 @@ if user_type == 'New User':
|
|
62 |
if st.button("Get Recommendations"):
|
63 |
recommendations = recommend_laptops(age=new_user_age, category=new_user_category, gender=new_user_gender)
|
64 |
st.subheader("Top 5 Recommended Laptops:")
|
65 |
-
for i, row in recommendations.iterrows():
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
f"Operating System: {row['Operating System']}\n"
|
75 |
-
f"Touchscreen: {row['Touchscreen']}\n"
|
76 |
-
f"Screen Size (in inch): {row['Screen Size (in inch)']}\n"
|
77 |
-
f"Weight (in kg): {row['Weight (in kg)']}\n"
|
78 |
-
f"Refresh Rate: {row['Refresh Rate']}\n"
|
79 |
-
f"Screen Resolution: {row['screen_resolution']}\n"
|
80 |
-
f"Company: {row['company']}\n"
|
81 |
-
f"Storage: {row['Storage']}\n"
|
82 |
-
f"Processor Name: {row['Processor name']}\n"
|
83 |
-
f"CPU Ranking: {row['CPU_ranking']}\n"
|
84 |
-
f"Battery Backup: {row['battery_backup']}\n"
|
85 |
-
f"GPU Name: {row['gpu name ']}\n"
|
86 |
-
f"GPU Benchmark: {row['gpu_benchmark']}\n")
|
87 |
-
st.markdown(f"[Buy Here]({row['link']})")
|
88 |
|
89 |
# User input for existing users
|
90 |
elif user_type == 'Existing User':
|
@@ -96,28 +82,14 @@ elif user_type == 'Existing User':
|
|
96 |
if existing_user_id:
|
97 |
recommendations = recommend_laptops(user_id=int(existing_user_id))
|
98 |
st.subheader(f"Top 5 Recommended Laptops for User {existing_user_id}:")
|
99 |
-
for i, row in recommendations.iterrows():
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
f"Operating System: {row['Operating System']}\n"
|
109 |
-
f"Touchscreen: {row['Touchscreen']}\n"
|
110 |
-
f"Screen Size (in inch): {row['Screen Size (in inch)']}\n"
|
111 |
-
f"Weight (in kg): {row['Weight (in kg)']}\n"
|
112 |
-
f"Refresh Rate: {row['Refresh Rate']}\n"
|
113 |
-
f"Screen Resolution: {row['screen_resolution']}\n"
|
114 |
-
f"Company: {row['company']}\n"
|
115 |
-
f"Storage: {row['Storage']}\n"
|
116 |
-
f"Processor Name: {row['Processor name']}\n"
|
117 |
-
f"CPU Ranking: {row['CPU_ranking']}\n"
|
118 |
-
f"Battery Backup: {row['battery_backup']}\n"
|
119 |
-
f"GPU Name: {row['gpu name ']}\n"
|
120 |
-
f"GPU Benchmark: {row['gpu_benchmark']}\n")
|
121 |
-
st.markdown(f"[Buy Here]({row['link']})")
|
122 |
else:
|
123 |
st.warning("Please enter a valid user ID.")
|
|
|
38 |
'Gender': [gender]
|
39 |
})
|
40 |
new_user_data = new_user_data.merge(laptop_df, how='cross')
|
41 |
+
new_user_data['Predicted_Rating'] = new_user_data.apply(lambda row: model.predict(10002, row['Laptop_ID']).est, axis=1)
|
42 |
recommendations = new_user_data.sort_values(by='Predicted_Rating', ascending=False).head(num_recommendations)
|
43 |
|
44 |
return recommendations
|
|
|
62 |
if st.button("Get Recommendations"):
|
63 |
recommendations = recommend_laptops(age=new_user_age, category=new_user_category, gender=new_user_gender)
|
64 |
st.subheader("Top 5 Recommended Laptops:")
|
65 |
+
# for i, row in recommendations.iterrows():
|
66 |
+
recommendations_table = recommendations[['Laptop_Name', 'Price (in Indian Rupees)', 'Type', 'Dedicated Graphic Memory Capacity',
|
67 |
+
'Processor Brand', 'SSD', 'RAM (in GB)', 'RAM Type', 'Expandable Memory',
|
68 |
+
'Operating System', 'Touchscreen', 'Screen Size (in inch)', 'Weight (in kg)',
|
69 |
+
'Refresh Rate', 'screen_resolution', 'company', 'Storage', 'Processor name',
|
70 |
+
'CPU_ranking', 'battery_backup', 'gpu name ', 'gpu_benchmark',
|
71 |
+
'ram_type_tokenized', 'gpu_processor_tokenized', 'link']]
|
72 |
+
|
73 |
+
st.table(recommendations_table)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# User input for existing users
|
76 |
elif user_type == 'Existing User':
|
|
|
82 |
if existing_user_id:
|
83 |
recommendations = recommend_laptops(user_id=int(existing_user_id))
|
84 |
st.subheader(f"Top 5 Recommended Laptops for User {existing_user_id}:")
|
85 |
+
# for i, row in recommendations.iterrows():
|
86 |
+
recommendations_table = recommendations[['Laptop_Name', 'Price (in Indian Rupees)', 'Type', 'Dedicated Graphic Memory Capacity',
|
87 |
+
'Processor Brand', 'SSD', 'RAM (in GB)', 'RAM Type', 'Expandable Memory',
|
88 |
+
'Operating System', 'Touchscreen', 'Screen Size (in inch)', 'Weight (in kg)',
|
89 |
+
'Refresh Rate', 'screen_resolution', 'company', 'Storage', 'Processor name',
|
90 |
+
'CPU_ranking', 'battery_backup', 'gpu name ', 'gpu_benchmark',
|
91 |
+
'ram_type_tokenized', 'gpu_processor_tokenized', 'link']]
|
92 |
+
|
93 |
+
st.table(recommendations_table)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
else:
|
95 |
st.warning("Please enter a valid user ID.")
|