Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,19 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
3 |
|
4 |
+
# โหลด Tokenizer และ Model
|
5 |
+
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# สร้าง NER Pipeline
|
10 |
+
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
# ฟังก์ชันที่รับข้อความและทำการวิเคราะห์
|
13 |
+
def analyze_text(text):
|
14 |
+
ner_results = ner_pipeline(text)
|
15 |
+
return [(entity['word'], entity['entity'], entity['score']) for entity in ner_results]
|
16 |
+
|
17 |
+
# สร้าง UI ด้วย Gradio
|
18 |
+
iface = gr.Interface(fn=analyze_text, inputs="text", outputs="dataframe", title="NER Analysis App")
|
19 |
+
iface.launch()
|