clementBE commited on
Commit
301006f
·
verified ·
1 Parent(s): 943d038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -78,7 +78,7 @@ def closest_basic_color(rgb):
78
  return closest_color
79
 
80
  def get_dominant_color(image, num_colors=5):
81
- image = image.resize((200, 200))
82
  pixels = np.array(image).reshape(-1, 3)
83
  kmeans = MiniBatchKMeans(n_clusters=num_colors, random_state=0, n_init=5)
84
  kmeans.fit(pixels)
@@ -109,9 +109,9 @@ def classify_zip_and_analyze_color(zip_file):
109
  except Exception:
110
  continue
111
 
112
- # Thumbnail for gallery (keep aspect ratio)
113
  thumb = image.copy()
114
- thumb.thumbnail((200, 200), Image.LANCZOS)
115
  thumbnails.append(thumb)
116
 
117
  # Classification
@@ -258,13 +258,7 @@ demo = gr.Interface(
258
  outputs=[
259
  gr.Dataframe(headers=["Filename", "Top 3 Predictions", "Confidence", "Dominant Color", "Basic Color", "Face Info"]),
260
  gr.File(label="Download XLSX"),
261
- gr.Gallery(
262
- label="Thumbnails",
263
- show_label=True,
264
- elem_id="thumbnail-gallery",
265
- columns=5,
266
- object_fit="contain" # keep proportions, no stretching
267
- ),
268
  gr.Image(type="pil", label="Basic Color Frequency"),
269
  gr.Image(type="pil", label="Top Prediction Distribution"),
270
  gr.Image(type="pil", label="Gender Distribution (Weighted ≤90%)"),
@@ -275,4 +269,4 @@ demo = gr.Interface(
275
  )
276
 
277
  if __name__ == "__main__":
278
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
78
  return closest_color
79
 
80
  def get_dominant_color(image, num_colors=5):
81
+ image = image.resize((300, 300))
82
  pixels = np.array(image).reshape(-1, 3)
83
  kmeans = MiniBatchKMeans(n_clusters=num_colors, random_state=0, n_init=5)
84
  kmeans.fit(pixels)
 
109
  except Exception:
110
  continue
111
 
112
+ # Thumbnail for gallery (higher-quality)
113
  thumb = image.copy()
114
+ thumb = thumb.resize((200, 200), Image.LANCZOS)
115
  thumbnails.append(thumb)
116
 
117
  # Classification
 
258
  outputs=[
259
  gr.Dataframe(headers=["Filename", "Top 3 Predictions", "Confidence", "Dominant Color", "Basic Color", "Face Info"]),
260
  gr.File(label="Download XLSX"),
261
+ gr.Gallery(label="Thumbnails", show_label=True, elem_id="thumbnail-gallery", columns=5),
 
 
 
 
 
 
262
  gr.Image(type="pil", label="Basic Color Frequency"),
263
  gr.Image(type="pil", label="Top Prediction Distribution"),
264
  gr.Image(type="pil", label="Gender Distribution (Weighted ≤90%)"),
 
269
  )
270
 
271
  if __name__ == "__main__":
272
+ demo.launch(server_name="0.0.0.0", server_port=7860)