Nucha commited on
Commit
f1331fb
·
verified ·
1 Parent(s): 9888afd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -33
app.py CHANGED
@@ -65,40 +65,18 @@ with col2:
65
  st.write(ner_results)
66
 
67
  with col3:
68
- # สร้าง NER Pipeline
69
- ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
70
 
71
- st.title("NER Annotation Tool")
72
- st.write("Highlight Named Entities and display them in a structured format.")
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
- # แสดงผลลัพธ์แบบ HTML
100
- st.markdown(highlighted_text, unsafe_allow_html=True)
 
 
 
101
 
102
- # แสดง Entities เป็น JSON
103
- st.json(entities)
 
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