Spaces:
Sleeping
Sleeping
File size: 1,452 Bytes
2a7729d c15480b 8ff3ba1 7abeff1 4579865 7abeff1 8ff3ba1 7abeff1 8ff3ba1 c15480b 7abeff1 c15480b 8ff3ba1 c15480b 7abeff1 c15480b 7abeff1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import os
os.system("python -m spacy download en_core_web_sm")
import streamlit as st
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
import spacy
from spacy import displacy
# โหลด Spacy Model
nlp = spacy.load("en_core_web_sm")
# โหลดโมเดล NER จาก Hugging Face
model_name = "Nucha/Nucha_SkillNER_BERT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
# สร้าง pipeline สำหรับ NER
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
# UI ด้วย Streamlit
st.title("NER Analysis with Nucha SkillNER BERT and displacy")
text = st.text_area("Enter text for NER analysis:")
if st.button("Analyze"):
ner_results = ner_pipeline(text)
# เตรียมข้อมูลสำหรับ displacy
ents = []
for entity in ner_results:
ents.append({
"start": entity['start'],
"end": entity['end'],
"label": entity['entity'],
})
# แสดงผล displacy ผ่าน Streamlit
options = {"colors": {"SKILL": "lightblue"}} # เพิ่มสีให้แต่ละ label ถ้าต้องการ
html = displacy.render({"text": text, "ents": ents}, style="ent", manual=True, options=options)
st.write(html, unsafe_allow_html=True)
|