Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
ner_pipeline = pipeline("ner", model="dslim/bert-base-NER", grouped_entities=True)
|
| 5 |
+
|
| 6 |
+
def highlight_entities(text):
|
| 7 |
+
entities = ner_pipeline(text)
|
| 8 |
+
# Gradio มีระบบ Highlight ข้อความให้อัตโนมัติถ้าเราส่งค่าไปแบบนี้
|
| 9 |
+
return {"text": text, "entities": entities}
|
| 10 |
+
|
| 11 |
+
demo = gr.Interface(
|
| 12 |
+
fn=highlight_entities,
|
| 13 |
+
inputs=gr.Textbox(placeholder="Enter sentence here..."),
|
| 14 |
+
outputs=gr.HighlightedText(),
|
| 15 |
+
title="Name Entity Recognition (NER) Finder"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
demo.launch()
|