Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model_name = "AdilHayat173/token_classifcation"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
9 |
+
nlp = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
10 |
+
|
11 |
+
st.title("Token Classification with Hugging Face")
|
12 |
+
|
13 |
+
# Text input from user
|
14 |
+
user_input = st.text_area("Enter text for token classification:", "")
|
15 |
+
|
16 |
+
if st.button("Classify Text"):
|
17 |
+
if user_input:
|
18 |
+
# Token classification
|
19 |
+
results = nlp(user_input)
|
20 |
+
|
21 |
+
# Display results
|
22 |
+
st.write("### Token Classification Results")
|
23 |
+
for entity in results:
|
24 |
+
st.write(f"**Token:** {entity['word']}")
|
25 |
+
st.write(f"**Label:** {entity['entity_group']}")
|
26 |
+
st.write(f"**Score:** {entity['score']:.4f}")
|
27 |
+
st.write("---")
|
28 |
+
else:
|
29 |
+
st.write("Please enter some text for classification.")
|