Ishaan Shah
commited on
Commit
•
51917a0
1
Parent(s):
267e3a7
Delete app.py
Browse files
app.py
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
4 |
-
from sklearn.cluster import KMeans
|
5 |
-
from fastapi import FastAPI
|
6 |
-
import joblib
|
7 |
-
|
8 |
-
def show_recommendations(product):
|
9 |
-
Y = vectorizer.transform([product])
|
10 |
-
prediction = model.predict(Y)
|
11 |
-
return prediction
|
12 |
-
|
13 |
-
def print_cluster(i):
|
14 |
-
for ind in order_centroids[i, :10]:
|
15 |
-
print(' %s' % terms[ind]),
|
16 |
-
|
17 |
-
def get_cluster_terms(cluster_index):
|
18 |
-
cluster_terms = [terms[ind] for ind in order_centroids[cluster_index, :10]]
|
19 |
-
return cluster_terms
|
20 |
-
|
21 |
-
model = joblib.load("./model.pkl")
|
22 |
-
vectorizer = joblib.load("./vectorizer.pkl")
|
23 |
-
|
24 |
-
order_centroids = model.cluster_centers_.argsort()[:, ::-1]
|
25 |
-
terms = vectorizer.get_feature_names_out()
|
26 |
-
|
27 |
-
st.title("Product Recommendation System")
|
28 |
-
|
29 |
-
# Input for product description
|
30 |
-
product_input = st.text_input("Enter a product description:", "")
|
31 |
-
|
32 |
-
# Button to trigger recommendation
|
33 |
-
if st.button("Get Recommendations"):
|
34 |
-
if product_input:
|
35 |
-
# Get cluster for the input product
|
36 |
-
cluster_index = show_recommendations(product_input)[0]
|
37 |
-
|
38 |
-
# Display the cluster number
|
39 |
-
st.write(f"The product belongs to cluster: {cluster_index}")
|
40 |
-
|
41 |
-
# Display the top terms in the cluster
|
42 |
-
cluster_terms = get_cluster_terms(cluster_index)
|
43 |
-
st.write("Top terms in this cluster:")
|
44 |
-
st.write(", ".join(cluster_terms))
|
45 |
-
else:
|
46 |
-
st.write("Please enter a product description.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|