Update app.py
Browse files
app.py
CHANGED
@@ -108,17 +108,21 @@ def display_images(image_paths, model_names, distances):
|
|
108 |
plt.show()
|
109 |
|
110 |
def recommend_images(img):
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
116 |
|
117 |
iface = gr.Interface(
|
118 |
fn=recommend_images,
|
119 |
inputs=gr.Image(label="Upload an image"),
|
120 |
-
outputs=gr.
|
121 |
title="Image Recommendation System",
|
122 |
description="Upload an image and get recommendations based on similarity."
|
123 |
)
|
124 |
-
iface.launch()
|
|
|
108 |
plt.show()
|
109 |
|
110 |
def recommend_images(img):
|
111 |
+
temp_img_path = 'temp_img.jpg'
|
112 |
+
img.save(temp_img_path)
|
113 |
+
|
114 |
+
recommended_images, recommended_model_names, recommended_distances = get_recommendations(temp_img_path, model, nbrs, image_paths, model_names)
|
115 |
+
|
116 |
+
recommendations = []
|
117 |
+
for i in range(len(recommended_images)):
|
118 |
+
recommendations.append(f"Rekomendasi {i+1}:\nGambar: {recommended_images[i]}\nModel: {recommended_model_names[i]}\nEuclidian Distance: {recommended_distances[i]:.2f}")
|
119 |
+
return recommended_images
|
120 |
|
121 |
iface = gr.Interface(
|
122 |
fn=recommend_images,
|
123 |
inputs=gr.Image(label="Upload an image"),
|
124 |
+
outputs=gr.Gallery(label="Rekomendasi"),
|
125 |
title="Image Recommendation System",
|
126 |
description="Upload an image and get recommendations based on similarity."
|
127 |
)
|
128 |
+
iface.launch()
|