That1BrainCell commited on
Commit
1469bd0
·
verified ·
1 Parent(s): d3f4a2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -36
app.py CHANGED
@@ -261,6 +261,8 @@ if st.button('Check for Infringement'):
261
  with tab1:
262
  with st.spinner('Processing...'):
263
 
 
 
264
  if not os.path.exists('/home/user/app/embeddings'):
265
  download_db()
266
  print("\u2713 Downloaded Database\n\n")
@@ -300,54 +302,54 @@ if st.button('Check for Infringement'):
300
  with col2:
301
  st.markdown(f"*Similar Text:* {similar_text}")
302
 
303
- if need_image == 'True':
304
- with st.spinner('Processing Images...'):
305
- emb_main , main_prod_imgs = get_image_embeddings(main_product)
306
- similar_prod = extract_similar_products(main_product)[0]
307
- emb_similar , similar_prod_imgs = get_image_embeddings(similar_prod)
308
 
309
- similarity_matrix = np.zeros((5, 5))
310
- for i in range(5):
311
- for j in range(5):
312
- similarity_matrix[i][j] = cosine_similarity([emb_main[i]], [emb_similar[j]])[0][0]
313
 
314
- st.subheader("Image Similarity")
315
- # Create an interactive heatmap
316
- fig = px.imshow(similarity_matrix,
317
- labels=dict(x=f"{similar_prod} Images", y=f"{main_product} Images", color="Similarity"),
318
- x=[f"Image {i+1}" for i in range(5)],
319
- y=[f"Image {i+1}" for i in range(5)],
320
- color_continuous_scale="Viridis")
321
 
322
- # Add title to the heatmap
323
- fig.update_layout(title="Image Similarity Heatmap")
324
 
325
- # Display the interactive heatmap
326
- st.plotly_chart(fig)
327
 
328
 
329
 
330
- @st.experimental_fragment
331
- def image_viewer():
332
- # Form to handle image selection
333
 
334
- st.subheader("Image Viewer")
335
 
336
- selected_row = st.selectbox('Select a row (Main Product Image)', [f'Image {i+1}' for i in range(5)])
337
- selected_col = st.selectbox('Select a column (Similar Product Image)', [f'Image {i+1}' for i in range(5)])
338
 
339
- # Get the selected indices from session state
340
- row_idx = int(selected_row.split()[1]) - 1
341
- col_idx = int(selected_col.split()[1]) - 1
342
 
343
- col1, col2 = st.columns(2)
344
 
345
- with col1:
346
- st.image(main_prod_imgs[row_idx], caption=f'Main Product Image {row_idx+1}', use_column_width=True)
347
- with col2:
348
- st.image(similar_prod_imgs[col_idx], caption=f'Similar Product Image {col_idx+1}', use_column_width=True)
349
 
350
- # Call the fragment
351
- image_viewer()
352
 
353
 
 
261
  with tab1:
262
  with st.spinner('Processing...'):
263
 
264
+ for path in os.listdir('/home/user/app'):
265
+ print(path)
266
  if not os.path.exists('/home/user/app/embeddings'):
267
  download_db()
268
  print("\u2713 Downloaded Database\n\n")
 
302
  with col2:
303
  st.markdown(f"*Similar Text:* {similar_text}")
304
 
305
+ if need_image == 'True':
306
+ with st.spinner('Processing Images...'):
307
+ emb_main , main_prod_imgs = get_image_embeddings(main_product)
308
+ similar_prod = extract_similar_products(main_product)[0]
309
+ emb_similar , similar_prod_imgs = get_image_embeddings(similar_prod)
310
 
311
+ similarity_matrix = np.zeros((5, 5))
312
+ for i in range(5):
313
+ for j in range(5):
314
+ similarity_matrix[i][j] = cosine_similarity([emb_main[i]], [emb_similar[j]])[0][0]
315
 
316
+ st.subheader("Image Similarity")
317
+ # Create an interactive heatmap
318
+ fig = px.imshow(similarity_matrix,
319
+ labels=dict(x=f"{similar_prod} Images", y=f"{main_product} Images", color="Similarity"),
320
+ x=[f"Image {i+1}" for i in range(5)],
321
+ y=[f"Image {i+1}" for i in range(5)],
322
+ color_continuous_scale="Viridis")
323
 
324
+ # Add title to the heatmap
325
+ fig.update_layout(title="Image Similarity Heatmap")
326
 
327
+ # Display the interactive heatmap
328
+ st.plotly_chart(fig)
329
 
330
 
331
 
332
+ @st.experimental_fragment
333
+ def image_viewer():
334
+ # Form to handle image selection
335
 
336
+ st.subheader("Image Viewer")
337
 
338
+ selected_row = st.selectbox('Select a row (Main Product Image)', [f'Image {i+1}' for i in range(5)])
339
+ selected_col = st.selectbox('Select a column (Similar Product Image)', [f'Image {i+1}' for i in range(5)])
340
 
341
+ # Get the selected indices from session state
342
+ row_idx = int(selected_row.split()[1]) - 1
343
+ col_idx = int(selected_col.split()[1]) - 1
344
 
345
+ col1, col2 = st.columns(2)
346
 
347
+ with col1:
348
+ st.image(main_prod_imgs[row_idx], caption=f'Main Product Image {row_idx+1}', use_column_width=True)
349
+ with col2:
350
+ st.image(similar_prod_imgs[col_idx], caption=f'Similar Product Image {col_idx+1}', use_column_width=True)
351
 
352
+ # Call the fragment
353
+ image_viewer()
354
 
355