-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
97 lines (85 loc) · 3.38 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import eel
import json
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
@eel.expose
def recieveDataToPython(jsToPy):
# this function is acessible from js
# print("Hellow,Function called from js")
print(jsToPy)
# print(jsToPy['ram'])
# 0) Get user data and make a df
data = {
"Name": ['User Req name'],
"Rating": [jsToPy['rating']],
# "Price Rs": [jsToPy['budget']],
"RAM Gb": [jsToPy['ram']],
"ROM Gb": [jsToPy['rom']],
"Expandable GB": [' '],
"Size Cm": [' '],
"Size Inch": [jsToPy['size']],
"R1 Cam MP": [jsToPy['camera']],
"R2 Cam MP": [' '],
"R3 Cam MP": [' '],
"R4 Cam MP": [' '],
"Battery Mah": [jsToPy['battery']],
"Processor": ' ',
"Image": ' '
}
userDf = pd.DataFrame(data)
# 1)Read the dataset
df = pd.read_csv('reference_Dataset_2.csv', encoding='unicode_escape')
# print (df.columns)
# 1.1)Append the dataframe
df = userDf.append(df, ignore_index=True)
# 2)Select Features
# features=['Price Rs','Rating','RAM Gb','ROM Gb','Size Inch','R1 Cam MP','Battery Mah']
# 3)Create a column which will contain all these feat
def combineFeatures(row):
return str(row['RAM Gb'])+" "+str(row['ROM Gb'])+" "+str(row['Size Inch'])+" "+str(row['R1 Cam MP'])+" "+str(row['Battery Mah'])
# this will create a seperate colm of combined features
df["combinedFeatures"] = df.apply(combineFeatures, axis=1)
# print (df['combinedFeatures'].head())
# 4) Now find the index which is more similar to our requirement
# now use cosine similarity
# create an object of countVectorizer
cv = CountVectorizer()
countMatrix = cv.fit_transform(df['combinedFeatures'])
# print (countMatrix).toarray()
similar = cosine_similarity(countMatrix)
similarPhones = list(enumerate(similar[0]))
# print (similarPhones)
# 5)Now sort the entries acc to similarity scores
sortedSimilarPhones = sorted(
# similarPhones, key=lambda x: x[1], reverse=True)
similarPhones, key=lambda x: x[1])
# print (sortedSimilarPhones)
# Now print the most similar 5 phones
x = 0
pyToJs = {}
for phone in sortedSimilarPhones:
if (df[df.index == phone[0]]['Name'].values[0] == 'User Req name'):
pass
else:
pyToJs[df[df.index == phone[0]]['Name'].values[0]] = {
'size': str(df[df.index == phone[0]]['Size Inch'].values[0]),
'ram': str(df[df.index == phone[0]]['RAM Gb'].values[0]),
'rom': str(df[df.index == phone[0]]['ROM Gb'].values[0]),
'camera': df[df.index == phone[0]]['R1 Cam MP'].values[0],
'budget': df[df.index == phone[0]]['Price Rs'].values[0],
'processor': df[df.index == phone[0]]['Processor'].values[0],
'rating': df[df.index == phone[0]]['Rating'].values[0],
'image': df[df.index == phone[0]]['Image'].values[0],
'battery': str(df[df.index == phone[0]]['Battery Mah'].values[0]),
}
#
x = x+1
if (x == 10):
break
# new code ends
# send back to frontend
eel.recieveBackToJs(pyToJs)
eel.init("frontend")
eel.start('login.html', size=(1920, 1080), port=8090)