bgaspra commited on
Commit
e6d2088
·
verified ·
1 Parent(s): 6ef5a6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -125,12 +125,18 @@ def recommend(image):
125
  # Display images with matplotlib
126
  display_images(recommended_images, recommended_model_names, recommended_distances)
127
 
128
- # Prepare text output for copying
129
- text_output = ""
130
- for model_name, distance in zip(recommended_model_names, recommended_distances):
131
- text_output += f"Model Name: {model_name}, Distance: {distance:.2f}\n"
 
 
 
 
 
 
132
 
133
- return text_output
134
 
135
  def display_images(image_paths, model_names, distances):
136
  plt.figure(figsize=(20, 10))
@@ -145,9 +151,9 @@ def display_images(image_paths, model_names, distances):
145
  interface = gr.Interface(
146
  fn=recommend,
147
  inputs=gr.Image(type="pil"),
148
- outputs=gr.Textbox(),
149
  title="Image Recommendation System",
150
  description="Upload an image and get 5 recommended similar images with model names and distances."
151
  )
152
 
153
- interface.launch()
 
125
  # Display images with matplotlib
126
  display_images(recommended_images, recommended_model_names, recommended_distances)
127
 
128
+ # Prepare HTML output for Gradio
129
+ html_output = ""
130
+ for img_path, model_name, distance in zip(recommended_images, recommended_model_names, recommended_distances):
131
+ html_output += f"""
132
+ <div style='display:inline-block; text-align:center; margin:10px;'>
133
+ <img src='file://{img_path}' style='width:200px; height:200px;'><br>
134
+ <b>Model Name:</b> {model_name}<br>
135
+ <b>Distance:</b> {distance:.2f}<br>
136
+ </div>
137
+ """
138
 
139
+ return html_output
140
 
141
  def display_images(image_paths, model_names, distances):
142
  plt.figure(figsize=(20, 10))
 
151
  interface = gr.Interface(
152
  fn=recommend,
153
  inputs=gr.Image(type="pil"),
154
+ outputs=gr.HTML(), # Use HTML output for better formatting
155
  title="Image Recommendation System",
156
  description="Upload an image and get 5 recommended similar images with model names and distances."
157
  )
158
 
159
+ interface.launch()