| import gradio as gr | |
| from transformers import pipeline | |
| from transformers import AutoTokenizer, AutoModelForTokenClassification | |
| tokenizer = AutoTokenizer.from_pretrained("51la5/roberta-large-NER") | |
| model = AutoModelForTokenClassification.from_pretrained("51la5/roberta-large-NER") | |
| classifier = pipeline("ner", model=model, tokenizer=tokenizer,grouped_entities=True) | |
| def get_ner(text): | |
| output = classifier(text) | |
| for elm in output: | |
| elm['entity'] = elm['entity_group'] | |
| return {"text": text, "entities": output} | |
| demo = gr.Interface(fn=get_ner, | |
| title="Atoqli nomlarni topish(NER)", | |
| inputs=gr.Textbox(lines=4, placeholder="Matinni kiriting!", label="Matn*"), | |
| outputs=gr.HighlightedText(label="Natija:") | |
| ) | |
| demo.launch() |