Spaces:
Build error
Build error
Commit ·
bba006e
1
Parent(s): 26787f1
app.py
Browse files
app.py
CHANGED
|
@@ -11,13 +11,15 @@ import gradio as gr
|
|
| 11 |
# Load the openAI's CLIP model
|
| 12 |
#model, preprocess = clip.load("ViT-B/32", jit=False)
|
| 13 |
#display output photo
|
| 14 |
-
def show_output_image(matched_images) :
|
| 15 |
image=[]
|
| 16 |
for photo_id in matched_images:
|
| 17 |
#photo_image_url = f"https://unsplash.com/photos/{photo_id}/download?w=280"
|
| 18 |
-
photo_image_url = f"https://unsplash.com/photos/{photo_id}?w=640"
|
| 19 |
#photo_image_url = f"https://unsplash.com/photos/{photo_id}?ixid=2yJhcHBfaWQiOjEyMDd9&fm=jpg"
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
img = Image.open(BytesIO(response.content))
|
| 22 |
#return img
|
| 23 |
image.append(img)
|
|
@@ -42,6 +44,9 @@ def image_search(search_text, search_image, option):
|
|
| 42 |
photo_ids = pd.read_csv("./photo_ids.csv")
|
| 43 |
photo_ids = list(photo_ids['photo_id'])
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
# taking features vectors
|
| 46 |
photo_features = np.load("./features.npy")
|
| 47 |
|
|
@@ -62,13 +67,13 @@ def image_search(search_text, search_image, option):
|
|
| 62 |
# Find the matched Images
|
| 63 |
matched_images = find_matches(text_features, photo_features, photo_ids, 4)
|
| 64 |
# ---- debug purpose ------#
|
| 65 |
-
print(matched_images[0])
|
| 66 |
-
id = matched_images[0]
|
| 67 |
-
photo_image_url = f"https://unsplash.com/photos/{id}/download?w=280"
|
| 68 |
-
print(photo_image_url)
|
| 69 |
#--------------------------#
|
| 70 |
|
| 71 |
-
return show_output_image(matched_images)
|
| 72 |
elif option == "Image-To-Image":
|
| 73 |
# Input Image for Search
|
| 74 |
with torch.no_grad():
|
|
|
|
| 11 |
# Load the openAI's CLIP model
|
| 12 |
#model, preprocess = clip.load("ViT-B/32", jit=False)
|
| 13 |
#display output photo
|
| 14 |
+
def show_output_image(matched_images, photos) :
|
| 15 |
image=[]
|
| 16 |
for photo_id in matched_images:
|
| 17 |
#photo_image_url = f"https://unsplash.com/photos/{photo_id}/download?w=280"
|
| 18 |
+
#photo_image_url = f"https://unsplash.com/photos/{photo_id}?w=640"
|
| 19 |
#photo_image_url = f"https://unsplash.com/photos/{photo_id}?ixid=2yJhcHBfaWQiOjEyMDd9&fm=jpg"
|
| 20 |
+
photo_found = photos[photos["photo_id"] == photo_id].iloc[0]
|
| 21 |
+
response = requests.get(photo_found["photo_image_url"] + "?w=640")
|
| 22 |
+
#response = requests.get(photo_image_url)
|
| 23 |
img = Image.open(BytesIO(response.content))
|
| 24 |
#return img
|
| 25 |
image.append(img)
|
|
|
|
| 44 |
photo_ids = pd.read_csv("./photo_ids.csv")
|
| 45 |
photo_ids = list(photo_ids['photo_id'])
|
| 46 |
|
| 47 |
+
# Photo dataset
|
| 48 |
+
photos = pd.read_csv("./photos.tsv000", sep="\t", header=0)
|
| 49 |
+
|
| 50 |
# taking features vectors
|
| 51 |
photo_features = np.load("./features.npy")
|
| 52 |
|
|
|
|
| 67 |
# Find the matched Images
|
| 68 |
matched_images = find_matches(text_features, photo_features, photo_ids, 4)
|
| 69 |
# ---- debug purpose ------#
|
| 70 |
+
#print(matched_images[0])
|
| 71 |
+
#id = matched_images[0]
|
| 72 |
+
#photo_image_url = f"https://unsplash.com/photos/{id}/download?w=280"
|
| 73 |
+
#print(photo_image_url)
|
| 74 |
#--------------------------#
|
| 75 |
|
| 76 |
+
return show_output_image(matched_images, photos)
|
| 77 |
elif option == "Image-To-Image":
|
| 78 |
# Input Image for Search
|
| 79 |
with torch.no_grad():
|