unojcn9f commited on
Commit
a33ca23
1 Parent(s): 610f512

Fix image caption mismatch

Browse files

If Danbooru API returns less `image_urls` than there are `captions`, then their sizes don't match, which caused some images to get wrong captions.

Files changed (1) hide show
  1. app.py +2 -4
app.py CHANGED
@@ -142,16 +142,14 @@ class SimilaritySearcher:
142
  neighbours_ids = [int(x) for x in neighbours_ids]
143
 
144
  captions = []
145
- for image_id, dist in zip(neighbours_ids, dists[0]):
146
- captions.append(f"{image_id}/{dist:.2f}")
147
-
148
  image_urls = []
149
- for image_id in neighbours_ids:
150
  current_url = danbooru_id_to_url(
151
  image_id, selected_ratings, api_username, api_key
152
  )
153
  if current_url is not None:
154
  image_urls.append(current_url)
 
155
  return list(zip(image_urls, captions))
156
 
157
 
 
142
  neighbours_ids = [int(x) for x in neighbours_ids]
143
 
144
  captions = []
 
 
 
145
  image_urls = []
146
+ for image_id, dist in zip(neighbours_ids, dists[0]):
147
  current_url = danbooru_id_to_url(
148
  image_id, selected_ratings, api_username, api_key
149
  )
150
  if current_url is not None:
151
  image_urls.append(current_url)
152
+ captions.append(f"{image_id}/{dist:.2f}")
153
  return list(zip(image_urls, captions))
154
 
155