Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,33 +44,36 @@ def get_dominant_color(image):
|
|
| 44 |
dominant_color = tuple(c / 255 for c in dominant_color) # Normalize RGB values to [0, 1]
|
| 45 |
return closest_color(dominant_color)
|
| 46 |
|
| 47 |
-
#
|
| 48 |
def get_outfit_recommendation(pred_class, color):
|
| 49 |
garment_recommendation = ''
|
| 50 |
-
color_recommendation = color_wheel.get(color,
|
| 51 |
|
| 52 |
-
if pred_class in [
|
| 53 |
-
garment_recommendation = '
|
| 54 |
-
elif pred_class ==
|
| 55 |
-
garment_recommendation = '
|
| 56 |
-
elif pred_class in [
|
| 57 |
-
garment_recommendation = '
|
| 58 |
-
elif pred_class in [
|
| 59 |
-
garment_recommendation = '
|
|
|
|
|
|
|
| 60 |
else:
|
| 61 |
-
garment_recommendation = '
|
| 62 |
|
| 63 |
return garment_recommendation, color_recommendation
|
| 64 |
|
|
|
|
| 65 |
def predict(image):
|
| 66 |
pred_class, pred_idx, outputs = learn.predict(image)
|
| 67 |
dominant_color = get_dominant_color(image)
|
| 68 |
-
garment_recommendation, color_recommendation = get_outfit_recommendation(
|
| 69 |
-
return f"
|
|
|
|
| 70 |
|
| 71 |
def gradio_predict(image):
|
| 72 |
if isinstance(image, np.ndarray):
|
| 73 |
-
# Convert numpy array to PIL Image
|
| 74 |
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 75 |
return predict(image)
|
| 76 |
|
|
@@ -82,4 +85,8 @@ interface = gr.Interface(
|
|
| 82 |
description="Upload an image of a garment to get a recommendation for a complementary outfit based on fashion theory."
|
| 83 |
)
|
| 84 |
|
| 85 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
dominant_color = tuple(c / 255 for c in dominant_color) # Normalize RGB values to [0, 1]
|
| 45 |
return closest_color(dominant_color)
|
| 46 |
|
| 47 |
+
# Get complementary outfit and colour
|
| 48 |
def get_outfit_recommendation(pred_class, color):
|
| 49 |
garment_recommendation = ''
|
| 50 |
+
color_recommendation = color_wheel.get(color, color)
|
| 51 |
|
| 52 |
+
if pred_class in [0, 2, 6]: # T-shirt/top, Pullover, Shirt
|
| 53 |
+
garment_recommendation = 'Trousers'
|
| 54 |
+
elif pred_class == 1: # Trouser
|
| 55 |
+
garment_recommendation = 'Top'
|
| 56 |
+
elif pred_class in [3, 4]: # Dress, Coat
|
| 57 |
+
garment_recommendation = 'Shoes'
|
| 58 |
+
elif pred_class in [5, 7, 9]: # Sandal, Sneaker, Ankle boot
|
| 59 |
+
garment_recommendation = 'Trousers'
|
| 60 |
+
elif pred_class == 8: # Bag
|
| 61 |
+
garment_recommendation = 'Top'
|
| 62 |
else:
|
| 63 |
+
garment_recommendation = 'Top'
|
| 64 |
|
| 65 |
return garment_recommendation, color_recommendation
|
| 66 |
|
| 67 |
+
#prediction function
|
| 68 |
def predict(image):
|
| 69 |
pred_class, pred_idx, outputs = learn.predict(image)
|
| 70 |
dominant_color = get_dominant_color(image)
|
| 71 |
+
garment_recommendation, color_recommendation = get_outfit_recommendation(pred_idx, dominant_color)
|
| 72 |
+
return f"Complementary item: {garment_recommendation} in {color_recommendation}"
|
| 73 |
+
|
| 74 |
|
| 75 |
def gradio_predict(image):
|
| 76 |
if isinstance(image, np.ndarray):
|
|
|
|
| 77 |
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 78 |
return predict(image)
|
| 79 |
|
|
|
|
| 85 |
description="Upload an image of a garment to get a recommendation for a complementary outfit based on fashion theory."
|
| 86 |
)
|
| 87 |
|
| 88 |
+
interface.launch()
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|