Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,17 @@ from keras.models import load_model
|
|
6 |
from keras.models import Model
|
7 |
from datasets import load_dataset
|
8 |
from sklearn.cluster import KMeans
|
9 |
-
import matplotlib.pyplot as
|
|
|
10 |
|
11 |
-
|
12 |
-
|
|
|
13 |
|
|
|
|
|
|
|
|
|
14 |
dataset = load_dataset("eybro/images")
|
15 |
split_dataset = dataset['train'].train_test_split(test_size=0.2, seed=42) # 80% train, 20% test
|
16 |
dataset['train'] = split_dataset['train']
|
@@ -67,7 +73,6 @@ def process_image(image):
|
|
67 |
def inference(image):
|
68 |
input_image = process_image(image)
|
69 |
|
70 |
-
|
71 |
nearest_neighbors = find_nearest_neighbors(encoded_images, input_image, top_n=5)
|
72 |
|
73 |
# Print the results
|
|
|
6 |
from keras.models import Model
|
7 |
from datasets import load_dataset
|
8 |
from sklearn.cluster import KMeans
|
9 |
+
import matplotlib.pyplot as pl
|
10 |
+
from huggingface_hub import hf_hub_download
|
11 |
|
12 |
+
# Download and load model and encoded images
|
13 |
+
model_path = hf_hub_download(repo_id="eybro/autoencoder", filename="autoencoder_model.keras")
|
14 |
+
data_path = hf_hub_download(repo_id="eybro/encoded_images", filename="X_encoded_compressed.npy")
|
15 |
|
16 |
+
autoencoder = load_model(model_path)
|
17 |
+
encoded_images = np.load(data_path)
|
18 |
+
|
19 |
+
# Load and split dataset
|
20 |
dataset = load_dataset("eybro/images")
|
21 |
split_dataset = dataset['train'].train_test_split(test_size=0.2, seed=42) # 80% train, 20% test
|
22 |
dataset['train'] = split_dataset['train']
|
|
|
73 |
def inference(image):
|
74 |
input_image = process_image(image)
|
75 |
|
|
|
76 |
nearest_neighbors = find_nearest_neighbors(encoded_images, input_image, top_n=5)
|
77 |
|
78 |
# Print the results
|