Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,9 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from sklearn.metrics.pairwise import euclidean_distances
|
| 4 |
import cv2
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
encoded_images = np.load("X_encoded_compressed.npy")
|
| 9 |
|
| 10 |
def find_nearest_neighbors(encoded_images, input_image, top_n=5):
|
|
@@ -34,14 +34,15 @@ def get_image(index):
|
|
| 34 |
return dataset["test"][index-split]
|
| 35 |
|
| 36 |
def process_image(image):
|
| 37 |
-
print(type(image))
|
| 38 |
img = np.array(image)
|
| 39 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 40 |
img = cv2.resize(img, (64, 64))
|
| 41 |
img = img.astype('float32')
|
| 42 |
-
img /= 255.0
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
return
|
| 45 |
|
| 46 |
def inference(image):
|
| 47 |
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from sklearn.metrics.pairwise import euclidean_distances
|
| 4 |
import cv2
|
| 5 |
+
from keras.models import load_model
|
| 6 |
|
| 7 |
+
autoencoder = tf.keras.models.load_model("autoencoder_model.keras")
|
|
|
|
| 8 |
encoded_images = np.load("X_encoded_compressed.npy")
|
| 9 |
|
| 10 |
def find_nearest_neighbors(encoded_images, input_image, top_n=5):
|
|
|
|
| 34 |
return dataset["test"][index-split]
|
| 35 |
|
| 36 |
def process_image(image):
|
|
|
|
| 37 |
img = np.array(image)
|
| 38 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 39 |
img = cv2.resize(img, (64, 64))
|
| 40 |
img = img.astype('float32')
|
| 41 |
+
img /= 255.0
|
| 42 |
+
img = np.expand_dims(img, axis=0)
|
| 43 |
+
encoded_features = autoencoder.predict(img)
|
| 44 |
|
| 45 |
+
return encoded_features
|
| 46 |
|
| 47 |
def inference(image):
|
| 48 |
|