vaniv commited on
Commit
ee3afa9
·
verified ·
1 Parent(s): 117c6de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -37,17 +37,21 @@ def get_complementary_color(rgb_color):
37
  h, s, v = colorsys.rgb_to_hsv(*rgb_color)
38
  complementary_h = (h + 0.5) % 1.0
39
  r, g, b = colorsys.hsv_to_rgb(complementary_h, s, v)
40
- return closest_color((r, g, b))
 
 
 
 
 
 
41
 
42
- def get_monochromatic_color(rgb_color):
43
- h, s, v = colorsys.rgb_to_hsv(*rgb_color)
44
- light_h = h
45
- dark_h = (h + 0.5) % 1.0
46
- light_rgb = colorsys.hsv_to_rgb(light_h, s, v)
47
- dark_rgb = colorsys.hsv_to_rgb(dark_h, s, v)
48
- light_color = closest_color(light_rgb)
49
- dark_color = closest_color(dark_rgb)
50
- return light_color, dark_color
51
 
52
 
53
  def get_outfit_recommendation(pred_class):
@@ -60,12 +64,17 @@ def get_outfit_recommendation(pred_class):
60
 
61
  def predict(image):
62
  pred_class, pred_idx, outputs = learn.predict(image)
63
- pred_class = class_names[pred_idx] # Convert index to class name
64
  dominant_color = get_dominant_color(image)
65
- complementary_color = get_complementary_color(dominant_color)
66
- mono_light_color, mono_dark_color = get_monochromatic_color(dominant_color)
67
  garment_recommendation = get_outfit_recommendation(pred_class)
68
- return f"Complementary item: {garment_recommendation} in {complementary_color}. Monochromatic options: {mono_light_color} or {mono_dark_color}."
 
 
 
 
 
 
 
69
 
70
  def gradio_predict(image):
71
  if isinstance(image, np.ndarray):
 
37
  h, s, v = colorsys.rgb_to_hsv(*rgb_color)
38
  complementary_h = (h + 0.5) % 1.0
39
  r, g, b = colorsys.hsv_to_rgb(complementary_h, s, v)
40
+ complementary_color = closest_color((r, g, b))
41
+
42
+ # Get shades or tones of the complementary color
43
+ complementary_palette = get_monochromatic_palette(complementary_color)
44
+
45
+ return complementary_color, complementary_palette
46
+
47
 
48
+ def get_monochromatic_palette(color_name, num_shades=3):
49
+ rgb_color = mcolors.CSS4_COLORS[color_name]
50
+ r, g, b = mcolors.hex2color(rgb_color)
51
+ hsv_colors = [colorsys.rgb_to_hsv(r, g, b)]
52
+ for i in range(1, num_shades):
53
+ hsv_colors.append((hsv_colors[-1][0], hsv_colors[-1][1], hsv_colors[-1][2] * (1 - 0.2 * i)))
54
+ return [mcolors.hsv_to_hex(color) for color in hsv_colors]
 
 
55
 
56
 
57
  def get_outfit_recommendation(pred_class):
 
64
 
65
  def predict(image):
66
  pred_class, pred_idx, outputs = learn.predict(image)
 
67
  dominant_color = get_dominant_color(image)
68
+ complementary_color, complementary_palette = get_complementary_color(dominant_color)
 
69
  garment_recommendation = get_outfit_recommendation(pred_class)
70
+
71
+ output = f"For your {pred_class.lower()}, consider pairing with a {garment_recommendation} in {complementary_color}."
72
+ output += "\n"
73
+ output += f"Monochromatic options:"
74
+ for color in complementary_palette:
75
+ output += f" {color},"
76
+ output = output[:-1] # Removes the last comma
77
+ output += "."
78
 
79
  def gradio_predict(image):
80
  if isinstance(image, np.ndarray):