FoodDesert commited on
Commit
c03c42a
1 Parent(s): 83610fc

Upload app.py

Browse files

fix a couple bugs related to how tags with parentheses are displayed.

Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -355,14 +355,15 @@ def create_html_tables_for_tags(subtable_heading, word_similarity_tuples, tag2co
355
  # Loop through the results and add table rows for each
356
  for word, sim in word_similarity_tuples:
357
  word_with_underscores = word.replace(' ', '_')
358
- count = tag2count.get(word_with_underscores, 0) # Get the count if available, otherwise default to 0
 
359
  tag_id, wiki_entry = tag2idwiki.get(word_with_underscores, (None, ''))
360
  # Check if tag_id and wiki_entry are valid
361
  if tag_id is not None and wiki_entry:
362
  # Construct the URL for the tag's wiki page
363
  wiki_url = f"https://e621.net/wiki_pages/{tag_id}"
364
  # Make the tag a hyperlink with a tooltip
365
- tag_element = f"<a href='{wiki_url}' target='_blank' title='{wiki_entry}'>{word}</a>"
366
  else:
367
  # Display the word without any hyperlink or tooltip
368
  tag_element = word
 
355
  # Loop through the results and add table rows for each
356
  for word, sim in word_similarity_tuples:
357
  word_with_underscores = word.replace(' ', '_')
358
+ word_with_escaped_parentheses = word.replace("\\(", "(").replace("\\)", ")").replace("(", "\\(").replace(")", "\\)")
359
+ count = tag2count.get(word_with_underscores.replace("\\(", "(").replace("\\)", ")"), 0) # Get the count if available, otherwise default to 0
360
  tag_id, wiki_entry = tag2idwiki.get(word_with_underscores, (None, ''))
361
  # Check if tag_id and wiki_entry are valid
362
  if tag_id is not None and wiki_entry:
363
  # Construct the URL for the tag's wiki page
364
  wiki_url = f"https://e621.net/wiki_pages/{tag_id}"
365
  # Make the tag a hyperlink with a tooltip
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