HamidBekam commited on
Commit
17410e3
1 Parent(s): eb1f289

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
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']}")