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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
3
 
4
  # โหลด Tokenizer และ Model
@@ -9,11 +9,11 @@ model = AutoModelForTokenClassification.from_pretrained(model_name)
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()
 
 
1
+ import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
3
 
4
  # โหลด Tokenizer และ Model
 
9
  # สร้าง NER Pipeline
10
  ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
11
 
12
+ # UI ด้วย Streamlit
13
+ st.title("NER Analysis App")
14
+ text = st.text_area("Enter text for NER analysis:")
 
15
 
16
+ if st.button("Analyze"):
17
+ ner_results = ner_pipeline(text)
18
+ for entity in ner_results:
19
+ st.write(f"Entity: {entity['word']}, Label: {entity['entity']}, Score: {entity['score']:.4f}")