NuchaITSkillNER / app.py
Nucha's picture
Update app.py
f1331fb verified
raw
history blame
3.29 kB
import streamlit as st
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
# โหลด Tokenizer และ Model
model_name = "Nucha/Nucha_ITSkillNER_BERT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
# สร้าง NER Pipeline
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
# UI ด้วย Streamlit
col1, col2, col3 = st.columns([4, 4, 4])
with col1:
st.header("Input")
default_text="""Job Description:
We are seeking a talented Software Engineer to join our dynamic team at Tech Innovations Inc. You will be responsible for designing, developing, and maintaining software applications that meet the needs of our clients.
Key Responsibilities:
Develop high-quality software design and architecture
Identify, prioritize, and execute tasks in the software development life cycle
Review and debug code
Collaborate with other developers and engineers to ensure software quality
Required Qualifications:
Bachelor’s degree in Computer Science or related field
Proven experience as a Software Engineer or similar role
Familiarity with Agile development methodologies
Proficiency in programming languages such as Java, Python, or C#
Strong problem-solving skills and the ability to work in a team
Preferred Qualifications:
"""
text = st.text_area("Enter text for NER analysis:", value=default_text, height=400, max_chars=None, key=None, help=None, placeholder=None)
analyze_button = st.button("Analyze")
st.write("""**Example Inputs:**
- Experience with cloud services (AWS, Azure)
- Knowledge of databases (SQL, NoSQL)
- Familiarity with front-end technologies (HTML, CSS, JavaScript)""")
with col2:
st.header("Result")
# ใช้ st.markdown กับ CSS เพื่อปรับขนาดฟอนต์
st.markdown("<span style='font-size: 14px;'>Press button [Analyze]</span>", unsafe_allow_html=True)
if analyze_button:
ner_results = ner_pipeline(text)
# Display results in a structured output block
if ner_results:
output_data = [{"Entity": entity['word'], "Label": entity['entity'], "Score": f"{entity['score']:.4f}"} for entity in ner_results]
st.table(output_data) # Display as a table
else:
st.write("No entities found.")
# ใช้ st.markdown กับ CSS เพื่อปรับขนาดฟอนต์
st.markdown("<span style='font-size: 14px;'>JSON</span>", unsafe_allow_html=True)
st.write(ner_results)
with col3:
st.header("Annotation")
if analyze_button and ner_results:
st.write("Edit detected entities:")
annotated_entities = []
for i, entity in enumerate(ner_results):
entity_text = st.text_input(f"Entity {i+1}", value=entity['word'])
entity_label = st.selectbox(f"Label {i+1}", ["O", "B-SKILL", "I-SKILL", "B-TOOL", "I-TOOL"], index=0)
annotated_entities.append({"Entity": entity_text, "Label": entity_label})
if st.button("Save Annotation"):
st.write("Saved Annotations:")
st.json(annotated_entities)