sort tags
Browse files
app.py
CHANGED
@@ -139,14 +139,12 @@ def create_tags(image, threshold):
|
|
139 |
indices = torch.where(probabilities > threshold)[0]
|
140 |
values = probabilities[indices]
|
141 |
|
142 |
-
temp = []
|
143 |
tag_score = dict()
|
144 |
for i in range(indices.size(0)):
|
145 |
-
temp.append([allowed_tags[indices[i]], values[i].item()])
|
146 |
tag_score[allowed_tags[indices[i]]] = values[i].item()
|
147 |
-
|
148 |
-
text_no_impl = ", ".join(
|
149 |
-
return text_no_impl,
|
150 |
|
151 |
with gr.Blocks() as demo:
|
152 |
gr.Markdown("""
|
|
|
139 |
indices = torch.where(probabilities > threshold)[0]
|
140 |
values = probabilities[indices]
|
141 |
|
|
|
142 |
tag_score = dict()
|
143 |
for i in range(indices.size(0)):
|
|
|
144 |
tag_score[allowed_tags[indices[i]]] = values[i].item()
|
145 |
+
sorted_tag_score = dict(sorted(tag_score.items(), key=lambda item: item[1], reverse=True))
|
146 |
+
text_no_impl = ", ".join(sorted_tag_score.keys())
|
147 |
+
return text_no_impl, sorted_tag_score
|
148 |
|
149 |
with gr.Blocks() as demo:
|
150 |
gr.Markdown("""
|