Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
|
|
|
|
3 |
|
4 |
|
5 |
encoded_images = np.load("X_encoded_compressed.npy")
|
@@ -31,8 +34,14 @@ def get_image(index):
|
|
31 |
return dataset["test"][index-split]
|
32 |
|
33 |
def process_image(image):
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
|
|
|
|
|
36 |
def inference(image):
|
37 |
|
38 |
input_image = process_image(image)
|
@@ -50,24 +59,11 @@ def inference(image):
|
|
50 |
for i in top4:
|
51 |
im = get_image(i)
|
52 |
print(im["label"], im["timestamp"])
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
plt.figure(figsize=(8, 8))
|
56 |
-
for i, (image1, image2) in enumerate(zip(top4[:2], top4[2:])):
|
57 |
-
ax = plt.subplot(2, n, i + 1)
|
58 |
-
image1 = get_image(image1)["image"]
|
59 |
-
image2 = get_image(image2)["image"]
|
60 |
-
|
61 |
-
plt.imshow(image1)
|
62 |
-
plt.gray()
|
63 |
-
ax.get_xaxis().set_visible(False)
|
64 |
-
ax.get_yaxis().set_visible(False)
|
65 |
-
|
66 |
-
ax = plt.subplot(2, n, i + 1 + n)
|
67 |
-
plt.imshow(image2)
|
68 |
-
plt.gray()
|
69 |
-
ax.get_xaxis().set_visible(False)
|
70 |
-
ax.get_yaxis().set_visible(False)
|
71 |
|
72 |
|
73 |
|
|
|
1 |
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")
|
|
|
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 |
|
43 |
+
return img
|
44 |
+
|
45 |
def inference(image):
|
46 |
|
47 |
input_image = process_image(image)
|
|
|
59 |
for i in top4:
|
60 |
im = get_image(i)
|
61 |
print(im["label"], im["timestamp"])
|
62 |
+
|
63 |
+
result_image = get_image(top4[0])
|
64 |
+
result = result_image['label'] + result_image['timestamp']
|
65 |
|
66 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
|
69 |
|