File size: 686 Bytes
17410e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import streamlit as st
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer

# Load model and tokenizer
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english"
model = AutoModelForTokenClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Define pipeline for named entity recognition
ner = pipeline('ner', model=model, tokenizer=tokenizer)

# Create a Streamlit app
st.title("Named Entity Recognition with Hugging Face and Streamlit")
text = st.text_input("Enter text:")
if text:
    result = ner(text)
    for item in result:
        st.write(f"{item['entity']} ({item['score']:.2f}): {item['word']}")