Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,17 @@ def get_complementary_color(rgb_color):
|
|
| 39 |
r, g, b = colorsys.hsv_to_rgb(complementary_h, s, v)
|
| 40 |
return closest_color((r, g, b))
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def get_outfit_recommendation(pred_class):
|
| 43 |
if pred_class == 'top':
|
| 44 |
return 'Jeans'
|
|
@@ -48,11 +59,13 @@ def get_outfit_recommendation(pred_class):
|
|
| 48 |
return 'Item'
|
| 49 |
|
| 50 |
def predict(image):
|
| 51 |
-
pred_class,
|
|
|
|
| 52 |
dominant_color = get_dominant_color(image)
|
| 53 |
complementary_color = get_complementary_color(dominant_color)
|
|
|
|
| 54 |
garment_recommendation = get_outfit_recommendation(pred_class)
|
| 55 |
-
return f"Complementary item: {garment_recommendation} in {complementary_color}"
|
| 56 |
|
| 57 |
def gradio_predict(image):
|
| 58 |
if isinstance(image, np.ndarray):
|
|
|
|
| 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):
|
| 54 |
if pred_class == 'top':
|
| 55 |
return 'Jeans'
|
|
|
|
| 59 |
return 'Item'
|
| 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):
|