RobotJelly commited on
Commit
547056a
·
1 Parent(s): 1d86891
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -36,7 +36,7 @@ def show_output_image(matched_images) :
36
  #photo_image_url = f"https://unsplash.com/photos/{photo_id}?ixid=2yJhcHBfaWQiOjEyMDd9&fm=jpg"
37
  #photo_found = photos[photos["photo_id"] == photo_id].iloc[0]
38
  #response = requests.get(photo_found["photo_image_url"] + "?w=640")
39
- response = requests.get(photo_image_url, stream=True).raw
40
  img = Image.open(BytesIO(response.content))
41
  #return img
42
  #photo_jpg = photo_id + '.jpg'
@@ -52,9 +52,11 @@ def encode_search_query(search_query, model, device):
52
  #text_encoded = model.encode_text(clip.tokenize(search_query).to(device))
53
  #text_encoded /= text_encoded.norm(dim=-1, keepdim=True)
54
  # Retrieve the feature vector from the GPU and convert it to a numpy array
55
- text_features = model.get_text_features(**inputs).detach().numpy()
56
  #text_features = model.get_text_features(**inputs).cpu().numpy()
57
- return text_features
 
 
58
  #return text_encoded.cpu().numpy()
59
 
60
  # Find all matched photos
@@ -79,13 +81,7 @@ def image_search(search_text, search_image, option):
79
 
80
  # Find the matched Images
81
  matched_images = find_matches(text_features, photo_features, photo_ids, 4)
82
- # ---- debug purpose ------#
83
- #print(matched_images[0])
84
- #id = matched_images[0]
85
- #photo_image_url = f"https://unsplash.com/photos/{id}/download?w=280"
86
- #print(photo_image_url)
87
- #--------------------------#
88
-
89
  return show_output_image(matched_images)
90
  elif option == "Image-To-Image":
91
  # Input Image for Search
 
36
  #photo_image_url = f"https://unsplash.com/photos/{photo_id}?ixid=2yJhcHBfaWQiOjEyMDd9&fm=jpg"
37
  #photo_found = photos[photos["photo_id"] == photo_id].iloc[0]
38
  #response = requests.get(photo_found["photo_image_url"] + "?w=640")
39
+ response = requests.get(photo_image_url, stream=True)
40
  img = Image.open(BytesIO(response.content))
41
  #return img
42
  #photo_jpg = photo_id + '.jpg'
 
52
  #text_encoded = model.encode_text(clip.tokenize(search_query).to(device))
53
  #text_encoded /= text_encoded.norm(dim=-1, keepdim=True)
54
  # Retrieve the feature vector from the GPU and convert it to a numpy array
55
+ #text_features = model.get_text_features(**inputs).detach().numpy()
56
  #text_features = model.get_text_features(**inputs).cpu().numpy()
57
+ text_features = model.get_text_features(**inputs).detach().numpy()
58
+ return np.array(text_features)
59
+ #return text_features
60
  #return text_encoded.cpu().numpy()
61
 
62
  # Find all matched photos
 
81
 
82
  # Find the matched Images
83
  matched_images = find_matches(text_features, photo_features, photo_ids, 4)
84
+
 
 
 
 
 
 
85
  return show_output_image(matched_images)
86
  elif option == "Image-To-Image":
87
  # Input Image for Search