ktllc commited on
Commit
e57bbcd
·
1 Parent(s): d4c665a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -15,6 +15,9 @@ print(device)
15
  Business_Listing = "Air Guide"
16
 
17
  def find_similarity(image1, image2, text_input):
 
 
 
18
  image_features = []
19
 
20
  # Preprocess and encode the two images
@@ -36,7 +39,7 @@ def find_similarity(image1, image2, text_input):
36
  # Calculate cosine similarity for each image
37
  for image_feature in image_features:
38
  image_feature /= image_feature.norm(dim=-1, keepdim=True)
39
- similarity = (text_features @ image_feature.T).cpu().numpy()
40
  similarities.append(similarity[0, 0])
41
 
42
  # Determine which image has a higher similarity to the text
 
15
  Business_Listing = "Air Guide"
16
 
17
  def find_similarity(image1, image2, text_input):
18
+ if image1 is None or image2 is None:
19
+ return None
20
+
21
  image_features = []
22
 
23
  # Preprocess and encode the two images
 
39
  # Calculate cosine similarity for each image
40
  for image_feature in image_features:
41
  image_feature /= image_feature.norm(dim=-1, keepdim=True)
42
+ similarity = (text_features @ image_feature.T).cpu().detach().numpy()
43
  similarities.append(similarity[0, 0])
44
 
45
  # Determine which image has a higher similarity to the text