Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -172,23 +172,23 @@ def get_predicted_attributes(image_urls, category):
|
|
172 |
if len(values) == 0:
|
173 |
continue
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
|
193 |
# Convert common_result into a dictionary
|
194 |
final = {}
|
@@ -209,7 +209,8 @@ def get_predicted_attributes(image_urls, category):
|
|
209 |
|
210 |
def generate_prompt(category: Optional[str], tags: Optional[Set[str]],
|
211 |
materials: Optional[List[Dict[str, int]]], attributes: Optional[List[Dict[str, str]]]) -> str:
|
212 |
-
|
|
|
213 |
formatted_attributes = [f"{attr['key']}: {attr['value']}" for attr in attributes] if attributes else []
|
214 |
|
215 |
formatted_string = "\\n".join(formatted_attributes) if formatted_attributes else "No attributes provided."
|
|
|
172 |
if len(values) == 0:
|
173 |
continue
|
174 |
|
175 |
+
# Adjust labels for the pipeline
|
176 |
+
attribute = attribute.replace("colartype", "collar").replace("sleevelength", "sleeve length").replace("fabricstyle", "fabric")
|
177 |
+
values = [f"{attribute}: {value.strip()}, clothing: {category}" for value in values]
|
178 |
+
|
179 |
+
# Get the predicted values for the attribute
|
180 |
+
responses = pipe(image_urls, candidate_labels=values)
|
181 |
+
most_common, score = get_most_common_label(responses)
|
182 |
+
common_result.append(most_common)
|
183 |
+
|
184 |
+
if attribute == "details":
|
185 |
+
# Process additional details labels if the score is higher than 0.8
|
186 |
+
for _ in range(2):
|
187 |
+
values = [value for value in values if value != f"{most_common}, clothing: {category}"]
|
188 |
+
responses = pipe(image_urls, candidate_labels=values)
|
189 |
+
most_common, score = get_most_common_label(responses)
|
190 |
+
if score > DETAILS_THRESHOLD * len(image_urls):
|
191 |
+
common_result.append(most_common)
|
192 |
|
193 |
# Convert common_result into a dictionary
|
194 |
final = {}
|
|
|
209 |
|
210 |
def generate_prompt(category: Optional[str], tags: Optional[Set[str]],
|
211 |
materials: Optional[List[Dict[str, int]]], attributes: Optional[List[Dict[str, str]]]) -> str:
|
212 |
+
|
213 |
+
print(attributes)
|
214 |
formatted_attributes = [f"{attr['key']}: {attr['value']}" for attr in attributes] if attributes else []
|
215 |
|
216 |
formatted_string = "\\n".join(formatted_attributes) if formatted_attributes else "No attributes provided."
|