Update app.py
Browse files
app.py
CHANGED
@@ -55,6 +55,7 @@ def score(main_product, main_url, product_count, link_count, search, logger, log
|
|
55 |
search_functions = {
|
56 |
'google': search_google,
|
57 |
'duckduckgo': search_duckduckgo,
|
|
|
58 |
'github': search_github,
|
59 |
'wikipedia': search_wikipedia
|
60 |
}
|
@@ -94,6 +95,12 @@ def score(main_product, main_url, product_count, link_count, search, logger, log
|
|
94 |
logger.write(str(data) + "\n")
|
95 |
log_area.text(logger.getvalue())
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
logger.write("\n\nCreating Main product Embeddings ---------->\n")
|
98 |
main_result, main_embedding = get_embeddings(main_url,tag_option)
|
99 |
log_area.text(logger.getvalue())
|
@@ -107,23 +114,32 @@ def score(main_product, main_url, product_count, link_count, search, logger, log
|
|
107 |
|
108 |
|
109 |
for product in data:
|
110 |
-
for link in data[product][:link_count]:
|
111 |
|
112 |
-
|
|
|
113 |
log_area.text(logger.getvalue())
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
-
|
116 |
-
for i in range(len(main_embedding)):
|
117 |
-
score = cosine_similarity(main_embedding[i], similar_embedding[i])
|
118 |
-
cosine_sim_scores.append((product, link, i, score))
|
119 |
log_area.text(logger.getvalue())
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
logger.write("--------------- DONE -----------------\n")
|
122 |
log_area.text(logger.getvalue())
|
123 |
return cosine_sim_scores, main_result
|
124 |
|
125 |
# Streamlit Interface
|
126 |
-
st.title("
|
|
|
127 |
|
128 |
# Inputs
|
129 |
main_product = st.text_input('Enter Main Product Name', 'Philips led 7w bulb')
|
@@ -151,12 +167,14 @@ if st.button('Check for Infringement'):
|
|
151 |
|
152 |
st.subheader("Cosine Similarity Scores")
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
157 |
tags = ['Introduction', 'Specifications', 'Product Overview', 'Safety Information', 'Installation Instructions', 'Setup and Configuration', 'Operation Instructions', 'Maintenance and Care', 'Troubleshooting', 'Warranty Information', 'Legal Information']
|
158 |
|
159 |
for product, link, index, value in cosine_sim_scores:
|
160 |
if not index:
|
161 |
st.write(f"Product: {product}, Link: {link}")
|
162 |
-
|
|
|
|
55 |
search_functions = {
|
56 |
'google': search_google,
|
57 |
'duckduckgo': search_duckduckgo,
|
58 |
+
'archive': search_archive,
|
59 |
'github': search_github,
|
60 |
'wikipedia': search_wikipedia
|
61 |
}
|
|
|
95 |
logger.write(str(data) + "\n")
|
96 |
log_area.text(logger.getvalue())
|
97 |
|
98 |
+
if len(data[product]) == 0:
|
99 |
+
logger.write("\n\nNo Product links Found Increase No of Links or Change Search Source\n")
|
100 |
+
log_area.text(logger.getvalue())
|
101 |
+
|
102 |
+
return [[product,'No Product links Found Increase Number of Links or Change Search Source',0,0]], False
|
103 |
+
|
104 |
logger.write("\n\nCreating Main product Embeddings ---------->\n")
|
105 |
main_result, main_embedding = get_embeddings(main_url,tag_option)
|
106 |
log_area.text(logger.getvalue())
|
|
|
114 |
|
115 |
|
116 |
for product in data:
|
|
|
117 |
|
118 |
+
if len(data[product])==0:
|
119 |
+
logger.write("\n\nNo Product links Found Increase No of Links or Change Search Source\n")
|
120 |
log_area.text(logger.getvalue())
|
121 |
+
|
122 |
+
cosine_sim_scores.append((product,'No Product links Found Increase Number of Links or Change Search Source',0,0))
|
123 |
+
|
124 |
+
else:
|
125 |
+
for link in data[product][:link_count]:
|
126 |
|
127 |
+
similar_result, similar_embedding = get_embeddings(link,tag_option)
|
|
|
|
|
|
|
128 |
log_area.text(logger.getvalue())
|
129 |
|
130 |
+
print(similar_embedding)
|
131 |
+
for i in range(len(main_embedding)):
|
132 |
+
score = cosine_similarity(main_embedding[i], similar_embedding[i])
|
133 |
+
cosine_sim_scores.append((product, link, i, score))
|
134 |
+
log_area.text(logger.getvalue())
|
135 |
+
|
136 |
logger.write("--------------- DONE -----------------\n")
|
137 |
log_area.text(logger.getvalue())
|
138 |
return cosine_sim_scores, main_result
|
139 |
|
140 |
# Streamlit Interface
|
141 |
+
st.title("Check Infringement")
|
142 |
+
|
143 |
|
144 |
# Inputs
|
145 |
main_product = st.text_input('Enter Main Product Name', 'Philips led 7w bulb')
|
|
|
167 |
|
168 |
st.subheader("Cosine Similarity Scores")
|
169 |
|
170 |
+
# = score(main_product, main_url, search, logger, log_output)
|
171 |
+
if tag_option == 'Single':
|
172 |
+
tags = ['Details']
|
173 |
+
else:
|
174 |
tags = ['Introduction', 'Specifications', 'Product Overview', 'Safety Information', 'Installation Instructions', 'Setup and Configuration', 'Operation Instructions', 'Maintenance and Care', 'Troubleshooting', 'Warranty Information', 'Legal Information']
|
175 |
|
176 |
for product, link, index, value in cosine_sim_scores:
|
177 |
if not index:
|
178 |
st.write(f"Product: {product}, Link: {link}")
|
179 |
+
if index!=0 and value!=0:
|
180 |
+
st.write(f"{tags[index]:<20} - Similarity: {value:.2f}")
|