FoodDesert commited on
Commit
42702f4
1 Parent(s): c03c42a

Upload app.py

Browse files

Avoid suggesting tags already in the prompt.

Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -366,7 +366,7 @@ def create_html_tables_for_tags(subtable_heading, word_similarity_tuples, tag2co
366
  tag_element = f"<a href='{wiki_url}' target='_blank' title='{wiki_entry}'>{word_with_escaped_parentheses}</a>"
367
  else:
368
  # Display the word without any hyperlink or tooltip
369
- tag_element = word
370
  # Include the tag element in the table row
371
  html_str += f"<tr><td style='border: none; padding: 5px; height: 20px;'>{tag_element}</td><td style='border: none; padding: 5px; height: 20px;'>{round(sim, 3)}</td><td style='border: none; padding: 5px; height: 20px;'>{count}</td></tr>"
372
 
@@ -488,8 +488,6 @@ def find_similar_tags(test_tags, similarity_weight, allow_nsfw_tags):
488
  end_pos = tag_info['end_pos']
489
  node_type = tag_info['node_type']
490
 
491
- #print(original_tag, modified_tag, start_pos, end_pos)
492
-
493
  if modified_tag in special_tags:
494
  bad_entities.append({"entity":"Special", "start":start_pos, "end":end_pos})
495
  continue
@@ -623,7 +621,8 @@ def find_similar_artists(original_tags_string, top_n, similarity_weight, allow_n
623
 
624
  suggested_tags_html_content += "<h1>Suggested Tags</h1>" # Heading for the table
625
  suggested_tags = get_tfidf_reduced_similar_tags([item["artist_matrix_tag"] for item in tag_data], allow_nsfw_tags)
626
- topnsuggestions = list(islice(suggested_tags.items(), 100))
 
627
  suggested_tags_html_content += create_html_tables_for_tags("Suggested Tag", topnsuggestions, find_similar_tags.tag2count, find_similar_tags.tag2idwiki)
628
 
629
  #Artist stuff
 
366
  tag_element = f"<a href='{wiki_url}' target='_blank' title='{wiki_entry}'>{word_with_escaped_parentheses}</a>"
367
  else:
368
  # Display the word without any hyperlink or tooltip
369
+ tag_element = word_with_escaped_parentheses
370
  # Include the tag element in the table row
371
  html_str += f"<tr><td style='border: none; padding: 5px; height: 20px;'>{tag_element}</td><td style='border: none; padding: 5px; height: 20px;'>{round(sim, 3)}</td><td style='border: none; padding: 5px; height: 20px;'>{count}</td></tr>"
372
 
 
488
  end_pos = tag_info['end_pos']
489
  node_type = tag_info['node_type']
490
 
 
 
491
  if modified_tag in special_tags:
492
  bad_entities.append({"entity":"Special", "start":start_pos, "end":end_pos})
493
  continue
 
621
 
622
  suggested_tags_html_content += "<h1>Suggested Tags</h1>" # Heading for the table
623
  suggested_tags = get_tfidf_reduced_similar_tags([item["artist_matrix_tag"] for item in tag_data], allow_nsfw_tags)
624
+ suggested_tags_filtered = OrderedDict((k, v) for k, v in suggested_tags.items() if k not in [entry["original_tag"] for entry in tag_data])
625
+ topnsuggestions = list(islice(suggested_tags_filtered.items(), 100))
626
  suggested_tags_html_content += create_html_tables_for_tags("Suggested Tag", topnsuggestions, find_similar_tags.tag2count, find_similar_tags.tag2idwiki)
627
 
628
  #Artist stuff