Spaces:
Sleeping
Sleeping
FoodDesert
commited on
Upload app.py
Browse fileschecking for double commas again
app.py
CHANGED
@@ -477,10 +477,6 @@ def find_similar_tags(test_tags, tag_to_context_similarity, context_similarity_w
|
|
477 |
bad_entities.append({"entity":"Duplicate", "start":start_pos, "end":end_pos})
|
478 |
continue
|
479 |
encountered_modified_tags.add(modified_tag)
|
480 |
-
|
481 |
-
if node_type == "double_comma":
|
482 |
-
bad_entities.append({"entity":"Double Comma", "start":start_pos, "end":end_pos})
|
483 |
-
continue
|
484 |
|
485 |
modified_tag_for_search = modified_tag.replace(' ','_')
|
486 |
similar_words = find_similar_tags.fasttext_small_model.most_similar(modified_tag_for_search, topn = 100)
|
@@ -581,6 +577,11 @@ def augment_bad_entities_with_regex(text):
|
|
581 |
index = match.start(1)
|
582 |
bad_entities.append({"entity": "Move Comma Inside Parentheses", "start": index, "end": index + 1})
|
583 |
|
|
|
|
|
|
|
|
|
|
|
584 |
return bad_entities
|
585 |
|
586 |
def escape_html(text):
|
@@ -618,9 +619,9 @@ def format_annotated_html(bad_entities, known_entities, text):
|
|
618 |
wiki_entry = entity.get('wiki_entry', '')
|
619 |
sanitized_wiki_entry = escape_html(wiki_entry) if wiki_entry else 'Unavailable'
|
620 |
if wiki_url: # Check if wiki_url is not empty
|
621 |
-
html_part = f'<a href="{wiki_url}" target="_blank" title="Count: {count}\tWiki: {sanitized_wiki_entry}" style="text-decoration: none;
|
622 |
else:
|
623 |
-
html_part = f'<span title="Count: {count}\tWiki: {sanitized_wiki_entry}" style="text-decoration: none;
|
624 |
else:
|
625 |
color = color_map.get(label, ("black", "white"))
|
626 |
html_part = f'<span style="background-color: {color[1]}; color: {color[0]};">{text[start:end]}</span>'
|
@@ -703,7 +704,7 @@ with gr.Blocks(css=css) as app:
|
|
703 |
with gr.Column(scale=1):
|
704 |
#image_path = os.path.join("https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main", "transparentsquirrel.png")
|
705 |
#gr.Image(label=" ", value=image_path, height=155, width=140)
|
706 |
-
gr.HTML('<div style="text-align: center;"><img src="https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main/mascotimages/transparentsquirrel.png" alt="Cute Mascot" style="
|
707 |
#gr.HTML("<br>" * 2) # Adjust the number of line breaks ("<br>") as needed to push the button down
|
708 |
#image_path = os.path.join('mascotimages', "transparentsquirrel.png")
|
709 |
#random_image_path = os.path.join('mascotimages', random.choice([f for f in os.listdir('mascotimages') if os.path.isfile(os.path.join('mascotimages', f))]))
|
|
|
477 |
bad_entities.append({"entity":"Duplicate", "start":start_pos, "end":end_pos})
|
478 |
continue
|
479 |
encountered_modified_tags.add(modified_tag)
|
|
|
|
|
|
|
|
|
480 |
|
481 |
modified_tag_for_search = modified_tag.replace(' ','_')
|
482 |
similar_words = find_similar_tags.fasttext_small_model.most_similar(modified_tag_for_search, topn = 100)
|
|
|
577 |
index = match.start(1)
|
578 |
bad_entities.append({"entity": "Move Comma Inside Parentheses", "start": index, "end": index + 1})
|
579 |
|
580 |
+
# Double Comma detection
|
581 |
+
for match in re.finditer(r',\s*,', text):
|
582 |
+
index = match.start()
|
583 |
+
bad_entities.append({"entity": "Double Comma", "start": index, "end": index + match.end() - match.start()})
|
584 |
+
|
585 |
return bad_entities
|
586 |
|
587 |
def escape_html(text):
|
|
|
619 |
wiki_entry = entity.get('wiki_entry', '')
|
620 |
sanitized_wiki_entry = escape_html(wiki_entry) if wiki_entry else 'Unavailable'
|
621 |
if wiki_url: # Check if wiki_url is not empty
|
622 |
+
html_part = f'<a href="{wiki_url}" target="_blank" title="Count: {count}\tWiki: {sanitized_wiki_entry}" style="text-decoration: none; cursor: pointer; font-style: italic;">{text[start:end]}</a>'
|
623 |
else:
|
624 |
+
html_part = f'<span title="Count: {count}\tWiki: {sanitized_wiki_entry}" style="text-decoration: none; cursor: help; font-style: italic;">{text[start:end]}</span>'
|
625 |
else:
|
626 |
color = color_map.get(label, ("black", "white"))
|
627 |
html_part = f'<span style="background-color: {color[1]}; color: {color[0]};">{text[start:end]}</span>'
|
|
|
704 |
with gr.Column(scale=1):
|
705 |
#image_path = os.path.join("https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main", "transparentsquirrel.png")
|
706 |
#gr.Image(label=" ", value=image_path, height=155, width=140)
|
707 |
+
gr.HTML('<div style="text-align: center;"><img src="https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main/mascotimages/transparentsquirrel.png" alt="Cute Mascot" style="height: 220px; width: auto; background: transparent;"></div><br>')
|
708 |
#gr.HTML("<br>" * 2) # Adjust the number of line breaks ("<br>") as needed to push the button down
|
709 |
#image_path = os.path.join('mascotimages', "transparentsquirrel.png")
|
710 |
#random_image_path = os.path.join('mascotimages', random.choice([f for f in os.listdir('mascotimages') if os.path.isfile(os.path.join('mascotimages', f))]))
|