Spaces:
Running
Running
FoodDesert
commited on
Commit
•
d3650cd
1
Parent(s):
5232b3e
Upload app.py
Browse filesAdded checking for duplicate tags. Shuffled components around a bit so that the settings that affect the tag suggestions are above the suggestions, and the settings that affect artist suggestions are above the artist suggestions.
app.py
CHANGED
@@ -414,6 +414,7 @@ def find_similar_tags(test_tags, similarity_weight, allow_nsfw_tags):
|
|
414 |
html_content += "<h1>Unknown Tags</h1>" # Heading for the table
|
415 |
tags_added = False
|
416 |
bad_entities = []
|
|
|
417 |
for tag_info in test_tags:
|
418 |
original_tag = tag_info['original_tag']
|
419 |
modified_tag = tag_info['modified_tag']
|
@@ -423,8 +424,15 @@ def find_similar_tags(test_tags, similarity_weight, allow_nsfw_tags):
|
|
423 |
#print(original_tag, modified_tag, start_pos, end_pos)
|
424 |
|
425 |
if modified_tag in special_tags:
|
|
|
426 |
continue
|
427 |
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
modified_tag_for_search = modified_tag.replace(' ','_')
|
429 |
similar_words = find_similar_tags.fasttext_small_model.most_similar(modified_tag_for_search, topn = 100)
|
430 |
result, seen = [], set(transformed_tags)
|
@@ -463,7 +471,7 @@ def find_similar_tags(test_tags, similarity_weight, allow_nsfw_tags):
|
|
463 |
result = sorted(result, key=lambda x: x[1], reverse=True)[:10]
|
464 |
html_content += create_html_tables_for_tags(modified_tag, result, find_similar_tags.tag2count, find_similar_tags.tag2idwiki)
|
465 |
|
466 |
-
bad_entities.append({"entity":"
|
467 |
|
468 |
tags_added=True
|
469 |
# If no tags were processed, add a message
|
@@ -538,20 +546,24 @@ def find_similar_artists(original_tags_string, top_n, similarity_weight, allow_n
|
|
538 |
with gr.Blocks() as app:
|
539 |
with gr.Group():
|
540 |
with gr.Row():
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
with gr.Row():
|
548 |
-
bad_tags_illustrated_string = gr.HighlightedText(label="Visual depiction of bad tags. Character offsets may be buggy.")
|
549 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
with gr.Column(scale=1):
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
galleries = []
|
556 |
for root, dirs, files in os.walk(sample_images_directory_path):
|
557 |
for name in dirs:
|
|
|
414 |
html_content += "<h1>Unknown Tags</h1>" # Heading for the table
|
415 |
tags_added = False
|
416 |
bad_entities = []
|
417 |
+
encountered_modified_tags = set()
|
418 |
for tag_info in test_tags:
|
419 |
original_tag = tag_info['original_tag']
|
420 |
modified_tag = tag_info['modified_tag']
|
|
|
424 |
#print(original_tag, modified_tag, start_pos, end_pos)
|
425 |
|
426 |
if modified_tag in special_tags:
|
427 |
+
bad_entities.append({"entity":"Special", "start":start_pos, "end":end_pos})
|
428 |
continue
|
429 |
|
430 |
+
if modified_tag in encountered_modified_tags:
|
431 |
+
bad_entities.append({"entity":"Duplicate", "start":start_pos, "end":end_pos})
|
432 |
+
continue
|
433 |
+
encountered_modified_tags.add(modified_tag)
|
434 |
+
|
435 |
+
|
436 |
modified_tag_for_search = modified_tag.replace(' ','_')
|
437 |
similar_words = find_similar_tags.fasttext_small_model.most_similar(modified_tag_for_search, topn = 100)
|
438 |
result, seen = [], set(transformed_tags)
|
|
|
471 |
result = sorted(result, key=lambda x: x[1], reverse=True)[:10]
|
472 |
html_content += create_html_tables_for_tags(modified_tag, result, find_similar_tags.tag2count, find_similar_tags.tag2idwiki)
|
473 |
|
474 |
+
bad_entities.append({"entity":"Unknown", "start":start_pos, "end":end_pos})
|
475 |
|
476 |
tags_added=True
|
477 |
# If no tags were processed, add a message
|
|
|
546 |
with gr.Blocks() as app:
|
547 |
with gr.Group():
|
548 |
with gr.Row():
|
549 |
+
with gr.Column(scale=3):
|
550 |
+
image_tags = gr.Textbox(label="Enter Prompt", placeholder="e.g. fox, outside, detailed background, ...")
|
551 |
+
bad_tags_illustrated_string = gr.HighlightedText(show_legend=True,label="Annotated Prompt")
|
552 |
+
with gr.Column(scale=1):
|
553 |
+
gr.HTML("<br>" * 2) # Adjust the number of line breaks ("<br>") as needed to push the button down
|
554 |
+
submit_button = gr.Button("Submit")
|
|
|
|
|
555 |
with gr.Row():
|
556 |
+
with gr.Column(scale=3):
|
557 |
+
with gr.Group():
|
558 |
+
with gr.Row():
|
559 |
+
similarity_weight = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Similarity weight")
|
560 |
+
allow_nsfw = gr.Checkbox(label="Allow NSFW Tags", value=False)
|
561 |
+
unseen_tags = gr.HTML(label="Unknown Tags", value=create_html_placeholder(title="Unknown Tags"))
|
562 |
with gr.Column(scale=1):
|
563 |
+
with gr.Group():
|
564 |
+
num_artists = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Number of artists")
|
565 |
+
top_artists = gr.HTML(label="Top Artists", value=create_html_placeholder(title="Top Artists"))
|
566 |
+
dynamic_prompts = gr.Textbox(label="Dynamic Prompts Format", info="For if you're using the Automatic1111 webui (https://github.com/AUTOMATIC1111/stable-diffusion-webui) with the Dynamic Prompts extension activated (https://github.com/adieyal/sd-dynamic-prompts) and want to try them all individually.")
|
567 |
galleries = []
|
568 |
for root, dirs, files in os.walk(sample_images_directory_path):
|
569 |
for name in dirs:
|