AnkitPatil commited on
Commit
562afe3
·
verified ·
1 Parent(s): 4f72b97

Upload 4 files

Browse files
Files changed (4) hide show
  1. amazon.png +0 -0
  2. amazon_product.csv +0 -0
  3. app.py +50 -0
  4. download.png +0 -0
amazon.png ADDED
amazon_product.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import nltk
4
+ from nltk.stem.snowball import SnowballStemmer
5
+ from sklearn.feature_extraction.text import TfidfVectorizer
6
+ from sklearn.metrics.pairwise import cosine_similarity
7
+ import streamlit as st
8
+ from PIL import Image
9
+
10
+ # Load the dataset
11
+ data = pd.read_csv('amazon_product.csv')
12
+
13
+ # Remove unnecessary columns
14
+ data = data.drop('id', axis=1)
15
+
16
+ # tokenizer and stemmer
17
+ stemmer = SnowballStemmer('english')
18
+ def tokenize_and_stem(text):
19
+ tokens = nltk.word_tokenize(text.lower())
20
+ stems = [stemmer.stem(t) for t in tokens]
21
+ return stems
22
+
23
+ # stemmed tokens column
24
+ data['stemmed_tokens'] = data.apply(lambda row: tokenize_and_stem(row['Title'] + ' ' + row['Description']), axis=1)
25
+
26
+ # TF-IDF vectorizer and cosine similarity function
27
+ tfidf_vectorizer = TfidfVectorizer(tokenizer=tokenize_and_stem)
28
+ def cosine_sim(text1, text2):
29
+ # tfidf_matrix = tfidf_vectorizer.fit_transform([text1, text2])
30
+ text1_concatenated = ' '.join(text1)
31
+ text2_concatenated = ' '.join(text2)
32
+ tfidf_matrix = tfidf_vectorizer.fit_transform([text1_concatenated, text2_concatenated])
33
+ return cosine_similarity(tfidf_matrix)[0][1]
34
+
35
+ # search function
36
+ def search_products(query):
37
+ query_stemmed = tokenize_and_stem(query)
38
+ data['similarity'] = data['stemmed_tokens'].apply(lambda x: cosine_sim(query_stemmed, x))
39
+ results = data.sort_values(by=['similarity'], ascending=False).head(10)[['Title', 'Description', 'Category']]
40
+ return results
41
+
42
+ # web app
43
+ img = Image.open('download.png')
44
+ st.image(img,width=600)
45
+ st.title("Intelligent Product Finder for Amazon")
46
+ query = st.text_input("Enter Product Name")
47
+ sumbit = st.button('Search')
48
+ if sumbit:
49
+ res = search_products(query)
50
+ st.write(res)
download.png ADDED