Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -42,6 +42,8 @@ with open(attributes_file_path, 'r') as file:
|
|
42 |
COLOURS_DICT = color_data['color_mapping']
|
43 |
ATTRIBUTES_DICT = attributes_data['attribute_mapping']
|
44 |
|
|
|
|
|
45 |
|
46 |
def shot(input, category, level):
|
47 |
output_dict = {}
|
@@ -157,13 +159,11 @@ def get_most_common_label(responses):
|
|
157 |
def get_predicted_attributes(image_urls, category):
|
158 |
# Assuming ATTRIBUTES_DICT and pipe are defined outside this function
|
159 |
attributes = list(ATTRIBUTES_DICT.get(category, {}).keys())
|
160 |
-
print(category, attributes)
|
161 |
|
162 |
# Mapping of possible values per attribute
|
163 |
common_result = []
|
164 |
for attribute in attributes:
|
165 |
values = ATTRIBUTES_DICT.get(category, {}).get(attribute, [])
|
166 |
-
print(attribute, values)
|
167 |
|
168 |
if len(values) == 0:
|
169 |
continue
|
@@ -176,7 +176,6 @@ def get_predicted_attributes(image_urls, category):
|
|
176 |
responses = pipe(image_urls, candidate_labels=values)
|
177 |
most_common, score = get_most_common_label(responses)
|
178 |
common_result.append(most_common)
|
179 |
-
print(common_result)
|
180 |
|
181 |
if attribute == "details":
|
182 |
# Process additional details labels if the score is higher than 0.8
|
@@ -184,7 +183,7 @@ def get_predicted_attributes(image_urls, category):
|
|
184 |
values = [value for value in values if value != f"{most_common}, clothing: {category}"]
|
185 |
responses = pipe(image_urls, candidate_labels=values)
|
186 |
most_common, score = get_most_common_label(responses)
|
187 |
-
if score >
|
188 |
common_result.append(most_common)
|
189 |
|
190 |
# Convert common_result into a dictionary
|
|
|
42 |
COLOURS_DICT = color_data['color_mapping']
|
43 |
ATTRIBUTES_DICT = attributes_data['attribute_mapping']
|
44 |
|
45 |
+
DETAILS_THRESHOLD = 0.8 # This is how high the total score of an additional detail attribute should be for it to be included
|
46 |
+
|
47 |
|
48 |
def shot(input, category, level):
|
49 |
output_dict = {}
|
|
|
159 |
def get_predicted_attributes(image_urls, category):
|
160 |
# Assuming ATTRIBUTES_DICT and pipe are defined outside this function
|
161 |
attributes = list(ATTRIBUTES_DICT.get(category, {}).keys())
|
|
|
162 |
|
163 |
# Mapping of possible values per attribute
|
164 |
common_result = []
|
165 |
for attribute in attributes:
|
166 |
values = ATTRIBUTES_DICT.get(category, {}).get(attribute, [])
|
|
|
167 |
|
168 |
if len(values) == 0:
|
169 |
continue
|
|
|
176 |
responses = pipe(image_urls, candidate_labels=values)
|
177 |
most_common, score = get_most_common_label(responses)
|
178 |
common_result.append(most_common)
|
|
|
179 |
|
180 |
if attribute == "details":
|
181 |
# Process additional details labels if the score is higher than 0.8
|
|
|
183 |
values = [value for value in values if value != f"{most_common}, clothing: {category}"]
|
184 |
responses = pipe(image_urls, candidate_labels=values)
|
185 |
most_common, score = get_most_common_label(responses)
|
186 |
+
if score > DETAILS_THRESHOLD:
|
187 |
common_result.append(most_common)
|
188 |
|
189 |
# Convert common_result into a dictionary
|