Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -65,40 +65,18 @@ with col2:
|
|
65 |
st.write(ner_results)
|
66 |
|
67 |
with col3:
|
68 |
-
|
69 |
-
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
def annotate_text(text):
|
75 |
-
ner_results = ner_pipeline(text)
|
76 |
-
|
77 |
-
# สร้าง Annotation Output
|
78 |
-
annotations = []
|
79 |
-
highlighted_text = text
|
80 |
-
|
81 |
-
for entity in ner_results:
|
82 |
-
word = entity['word']
|
83 |
-
entity_label = entity['entity']
|
84 |
-
score = round(entity['score'], 4)
|
85 |
-
|
86 |
-
# สร้าง Dictionary ของ Entity
|
87 |
-
annotations.append({"Entity": word, "Label": entity_label, "Score": score})
|
88 |
-
|
89 |
-
# Highlight คำที่เป็น Entity
|
90 |
-
highlighted_text = highlighted_text.replace(word, f'<mark style="background-color: yellow">{word} ({entity_label})</mark>')
|
91 |
-
|
92 |
-
return highlighted_text, annotations
|
93 |
-
|
94 |
-
text = st.text_area("Enter text for NER analysis:", height=200)
|
95 |
-
|
96 |
-
if st.button("Analyze"):
|
97 |
-
highlighted_text, entities = annotate_text(text)
|
98 |
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
101 |
|
102 |
-
|
103 |
-
|
|
|
104 |
|
|
|
65 |
st.write(ner_results)
|
66 |
|
67 |
with col3:
|
68 |
+
st.header("Annotation")
|
|
|
69 |
|
70 |
+
if analyze_button and ner_results:
|
71 |
+
st.write("Edit detected entities:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
annotated_entities = []
|
74 |
+
for i, entity in enumerate(ner_results):
|
75 |
+
entity_text = st.text_input(f"Entity {i+1}", value=entity['word'])
|
76 |
+
entity_label = st.selectbox(f"Label {i+1}", ["O", "B-SKILL", "I-SKILL", "B-TOOL", "I-TOOL"], index=0)
|
77 |
+
annotated_entities.append({"Entity": entity_text, "Label": entity_label})
|
78 |
|
79 |
+
if st.button("Save Annotation"):
|
80 |
+
st.write("Saved Annotations:")
|
81 |
+
st.json(annotated_entities)
|
82 |
|