bgaspra commited on
Commit
933bd54
·
verified ·
1 Parent(s): 98d3e8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
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
- recommended_images, recommended_model_names, recommended_distances = get_recommendations(img, model, nbrs, image_paths, model_names)
112
- recommendations = []
113
- for i in range(len(recommended_images)):
114
- recommendations.append(f"Rekomendasi {i+1}:\nGambar: {Image.open(recommended_images[i])}\nModel: {recommended_model_names[i]}\nEuclidian Distance: {recommended_distances[i]:.2f}")
115
- return recommendations
 
 
 
 
116
 
117
  iface = gr.Interface(
118
  fn=recommend_images,
119
  inputs=gr.Image(label="Upload an image"),
120
- outputs=gr.Textbox(label="Rekomendasi", lines=10),
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()