Spaces:
Runtime error
Runtime error
HamidBekam
commited on
Commit
•
17410e3
1
Parent(s):
eb1f289
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english"
|
6 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define pipeline for named entity recognition
|
10 |
+
ner = pipeline('ner', model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
# Create a Streamlit app
|
13 |
+
st.title("Named Entity Recognition with Hugging Face and Streamlit")
|
14 |
+
text = st.text_input("Enter text:")
|
15 |
+
if text:
|
16 |
+
result = ner(text)
|
17 |
+
for item in result:
|
18 |
+
st.write(f"{item['entity']} ({item['score']:.2f}): {item['word']}")
|