ktllc commited on
Commit
21edb75
·
1 Parent(s): 72d065f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -21,8 +21,7 @@ def find_similarity(base64_image, text_input):
21
  image = Image.open(BytesIO(image_bytes))
22
 
23
  # Preprocess the image
24
- # image = preprocess(image).unsqueeze(0).to(device)
25
- image = preprocess(image).to(device)
26
 
27
  # Prepare input text
28
  text_tokens = clip.tokenize([text_input]).to(device)
@@ -37,7 +36,7 @@ def find_similarity(base64_image, text_input):
37
  # Normalize features and calculate similarity
38
  image_features /= image_features.norm(dim=-1, keepdim=True)
39
  text_features /= text_features.norm(dim=-1, keepdim=True)
40
- similarity = (text_features @ image_features.T).cpu().numpy()
41
 
42
  return similarity
43
 
 
21
  image = Image.open(BytesIO(image_bytes))
22
 
23
  # Preprocess the image
24
+ image = preprocess(image).unsqueeze(0).to(device)
 
25
 
26
  # Prepare input text
27
  text_tokens = clip.tokenize([text_input]).to(device)
 
36
  # Normalize features and calculate similarity
37
  image_features /= image_features.norm(dim=-1, keepdim=True)
38
  text_features /= text_features.norm(dim=-1, keepdim=True)
39
+ similarity = (text_features @ image_features.T).squeeze(0).cpu().numpy()
40
 
41
  return similarity
42