-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworking.txt
13 lines (7 loc) · 2.87 KB
/
working.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
The code starts by importing the required libraries including Streamlit, Pandas, Numpy, and Scikit-learn. It also imports some functions from the "funcs" module and the "components" module of Streamlit.
After that, it reads a CSV file named "Electronics_data.csv" and fills the missing values with the mean of each column.
The code then creates a TfidfVectorizer object and fits it to the "Title" column of the "edata" dataframe. It transforms the "Title" column into a matrix of tf-idf features using the TfidfVectorizer object, and calculates the cosine similarities between all pairs of products in the "Title" column.
Next, there are two functions defined: "get_similar_products" and "get_image_url". The "get_similar_products" function takes an age and an optional parameter "n" and returns the "n" most similar products to the given age. It does this by first filtering the "edata" dataframe by age and getting the indices of the filtered rows. Then, it calculates the mean cosine similarities between the filtered rows and all other products in the dataset. It returns the "n" products with the highest cosine similarity scores. The "get_image_url" function takes a product title and returns its image URL from the "edata" dataframe.
The "main" function starts by configuring the layout of the page and initializing some variables. It creates a sidebar with a header and three options for the user to choose from. The first option is "Recommend from similar items", the second is "Recommendations based on customer purchase history", and the third is "Product Captioning".
When the user selects the "Recommend from similar items" option, the code reads two CSV files named "articles.csv" and "articles_rcmnds.csv". It also defines a list of model names and a list of model descriptions. The code then creates a button in the sidebar that allows the user to get a random item. When the user clicks on this button, the code selects a random item from the "articles_rcmnds" dataframe and displays its image and description in the sidebar. It then calls several functions to get recommendations for similar items based on image embeddings, text embeddings, descriptive features, a TensorFlow Recommenders model, and a combination of all embeddings. For each model, the code displays the model name, the similarity score, and an image of the recommended item. If the model is based on text embeddings, it also displays the description of the recommended item.
When the user selects the "Product Captioning" option, the code reads a CSV file named "caption_desc_embeds.csv". It also creates a button in the sidebar that allows the user to get a random item. When the user clicks on this button, the code selects a random item from the "caption_desc_embeds" dataframe and displays its image in the sidebar. It then uses a transformer-based model to generate a product caption based on the item's image and displays it on the page.