user-agent commited on
Commit
7323889
1 Parent(s): 276e058

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -11
app.py CHANGED
@@ -101,26 +101,43 @@ def shot(input, category, level):
101
  # subColour = responses[0][0]['label'].split(" clothing:")[0]
102
 
103
  # return subColour, mainColour, responses[0][0]['score']
104
- @spaces.GPU
105
- def get_colour(image_urls, category):
106
- colourLabels = list(COLOURS_DICT.keys())
107
- for i in range(len(colourLabels)):
108
- colourLabels[i] = colourLabels[i] + " clothing: " + category
109
 
 
 
 
 
110
  print("Colour Labels:", colourLabels) # Debug: Print colour labels
111
  print("Image URLs:", image_urls) # Debug: Print image URLs
112
 
113
- responses = pipe(image_urls, candidate_labels=colourLabels)
114
- mainColour = responses[0][0]['label'].split(" clothing:")[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  if mainColour not in COLOURS_DICT:
117
  return None, None, None
118
 
119
- labels = COLOURS_DICT[mainColour]
120
- for i in range(len(labels)):
121
- labels[i] = labels[i] + " clothing: " + category
122
-
123
  print("Labels for pipe:", labels) # Debug: Confirm labels are correct
 
124
  responses = pipe(image_urls, candidate_labels=labels)
125
  subColour = responses[0][0]['label'].split(" clothing:")[0]
126
 
@@ -128,6 +145,7 @@ def get_colour(image_urls, category):
128
 
129
 
130
 
 
131
  @spaces.GPU
132
  def get_predicted_attributes(image_urls, category):
133
  # Assuming ATTRIBUTES_DICT and pipe are defined outside this function
 
101
  # subColour = responses[0][0]['label'].split(" clothing:")[0]
102
 
103
  # return subColour, mainColour, responses[0][0]['score']
 
 
 
 
 
104
 
105
+ @spaces.GPU
106
+ def get_colour(image_urls, category):
107
+ # Prepare color labels
108
+ colourLabels = [f"{color} clothing: {category}" for color in COLOURS_DICT.keys()]
109
  print("Colour Labels:", colourLabels) # Debug: Print colour labels
110
  print("Image URLs:", image_urls) # Debug: Print image URLs
111
 
112
+ # Split labels into two batches
113
+ mid_index = len(colourLabels) // 2
114
+ first_batch = colourLabels[:mid_index]
115
+ second_batch = colourLabels[mid_index:]
116
+
117
+ # Process the first batch
118
+ responses_first_batch = pipe(image_urls, candidate_labels=first_batch)
119
+ # Get the top 3 from the first batch
120
+ top3_first_batch = sorted(responses_first_batch[0], key=lambda x: x['score'], reverse=True)[:3]
121
+
122
+ # Process the second batch
123
+ responses_second_batch = pipe(image_urls, candidate_labels=second_batch)
124
+ # Get the top 3 from the second batch
125
+ top3_second_batch = sorted(responses_second_batch[0], key=lambda x: x['score'], reverse=True)[:3]
126
+
127
+ # Combine the top 3 from each batch
128
+ combined_top6 = top3_first_batch + top3_second_batch
129
+ # Get the final top 3 from the combined list
130
+ final_top3 = sorted(combined_top6, key=lambda x: x['score'], reverse=True)[:3]
131
+
132
+ mainColour = final_top3[0]['label'].split(" clothing:")[0]
133
 
134
  if mainColour not in COLOURS_DICT:
135
  return None, None, None
136
 
137
+ # Get sub-colors for the main color
138
+ labels = [f"{label} clothing: {category}" for label in COLOURS_DICT[mainColour]]
 
 
139
  print("Labels for pipe:", labels) # Debug: Confirm labels are correct
140
+
141
  responses = pipe(image_urls, candidate_labels=labels)
142
  subColour = responses[0][0]['label'].split(" clothing:")[0]
143
 
 
145
 
146
 
147
 
148
+
149
  @spaces.GPU
150
  def get_predicted_attributes(image_urls, category):
151
  # Assuming ATTRIBUTES_DICT and pipe are defined outside this function