NerRoB-czech / app.py
AlzbetaStrompova
adjust colors
19e9ab7
raw
history blame
1.43 kB
import json
import gradio as gr
from website_script import load, run
tokenizer, model, gazetteers_for_matching = load()
examples = [
["Masarykova univerzita se nachází v Brně .", None],
["Barack Obama navštívil Prahu minulý týden .", None],
["Angela Merkelová se setkala s francouzským prezidentem v Paříži .", None],
["Nobelova cena za fyziku byla udělena týmu vědců z MIT .", None]
]
def ner(text, file_names):
result = run(tokenizer, model, gazetteers_for_matching, text, file_names)
return {"text": text, "entities": result}
with gr.Blocks(css="./style.css", theme=gr.themes.Default(primary_hue="blue", secondary_hue="sky")) as demo:
gr.Interface(ner,
gr.Textbox(lines=10, placeholder="Enter sentence here..."),
# gr.HighlightedText(show_legend=True, color_map={"PER": "red", "ORG": "green", "LOC": "blue"}),
gr.HighlightedText(show_legend=True, color_map={"PER": "#f57d7d", "ORG": "#2cf562", "LOC": "#86aafc"}, elem_id="highlighted_text"),
examples=examples,
title="NerROB-czech",
description="This is an implementation of a Named Entity Recognition model for the Czech language using gazetteers.",
allow_flagging="never",
additional_inputs=gr.File(label="Upload a JSON file containing gazetteers", file_count="multiple", file_types=[".json"]),
)
if __name__ == "__main__":
demo.launch()