Spaces:
Build error
Build error
Commit
·
27b8fd9
1
Parent(s):
62bd40d
app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ from pathlib import Path
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
import torch
|
| 6 |
-
import clip
|
| 7 |
from PIL import Image
|
| 8 |
from io import BytesIO
|
| 9 |
import requests
|
|
@@ -53,7 +52,7 @@ def encode_search_query(search_query, model, device):
|
|
| 53 |
#text_encoded = model.encode_text(clip.tokenize(search_query).to(device))
|
| 54 |
#text_encoded /= text_encoded.norm(dim=-1, keepdim=True)
|
| 55 |
# Retrieve the feature vector from the GPU and convert it to a numpy array
|
| 56 |
-
|
| 57 |
#return text_encoded.cpu().numpy()
|
| 58 |
|
| 59 |
# Find all matched photos
|
|
@@ -87,16 +86,16 @@ def image_search(search_text, search_image, option):
|
|
| 87 |
|
| 88 |
return show_output_image(matched_images)
|
| 89 |
elif option == "Image-To-Image":
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
# Find the matched Images
|
| 97 |
-
|
| 98 |
#is_input_image = True
|
| 99 |
-
|
| 100 |
|
| 101 |
gr.Interface(fn=image_search,
|
| 102 |
inputs=[gr.inputs.Textbox(lines=7, label="Input Text"),
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
import torch
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
from io import BytesIO
|
| 8 |
import requests
|
|
|
|
| 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 |
+
return model.get_text_features(**inputs).cpu().numpy()
|
| 56 |
#return text_encoded.cpu().numpy()
|
| 57 |
|
| 58 |
# Find all matched photos
|
|
|
|
| 86 |
|
| 87 |
return show_output_image(matched_images)
|
| 88 |
elif option == "Image-To-Image":
|
| 89 |
+
# Input Image for Search
|
| 90 |
+
with torch.no_grad():
|
| 91 |
+
processed_image = processor(text=None, images=search_image, return_tensors="pt", padding=True)["pixel_values"]
|
| 92 |
+
image_feature = model.get_image_features(processed_image.to(device))
|
| 93 |
+
image_feature /= image_feature.norm(dim=-1, keepdim=True)
|
| 94 |
+
image_feature = image_feature.cpu().numpy()
|
| 95 |
# Find the matched Images
|
| 96 |
+
matched_images = find_matches(image_feature, photo_features, photo_ids, 4)
|
| 97 |
#is_input_image = True
|
| 98 |
+
return show_output_image(matched_images)
|
| 99 |
|
| 100 |
gr.Interface(fn=image_search,
|
| 101 |
inputs=[gr.inputs.Textbox(lines=7, label="Input Text"),
|