Added proper details impl

#6
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -166,13 +166,20 @@ def get_predicted_attributes(image_urls, category):
166
  # Get the predicted values for the attribute
167
  responses = pipe(image_urls, candidate_labels=values_formatted)
168
  result = [response[0]['label'].split(", clothing:")[0] for response in responses]
169
-
170
- # If attribute is details, then get the top 2 most common labels
171
- if attribute_formatted == "details":
172
- result += [response[1]['label'].split(", clothing:")[0] for response in responses]
173
- common_result.append(Counter(result).most_common(2))
174
- else:
175
- common_result.append(Counter(result).most_common(1))
 
 
 
 
 
 
 
176
 
177
  # Clean up the results into one long string
178
  for i, result in enumerate(common_result):
 
166
  # Get the predicted values for the attribute
167
  responses = pipe(image_urls, candidate_labels=values_formatted)
168
  result = [response[0]['label'].split(", clothing:")[0] for response in responses]
169
+ common_result.append(Counter(result).most_common(1))
170
+
171
+ # If attribute is details, then remove the obtained label from the values, and get the next most common
172
+ if attribute == "details":
173
+ values_formatted.remove(result[0])
174
+ responses = pipe(image_urls, candidate_labels=values_formatted)
175
+ i = 0
176
+ while len(responses) > 0 and responses[0][0]['score'] > 0.8 and i < 2:
177
+ result = [response[0]['label'].split(", clothing:")[0] for response in responses]
178
+ common_result.append(Counter(result).most_common(1))
179
+
180
+ responses = pipe(image_urls, candidate_labels=values_formatted)
181
+ i += 1
182
+
183
 
184
  # Clean up the results into one long string
185
  for i, result in enumerate(common_result):