Nucha commited on
Commit
8ff3ba1
·
verified ·
1 Parent(s): 4579865

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -1,4 +1,19 @@
1
- import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()