Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
model_name = "ZombitX64/Thai-sentiment-e5"
|
| 5 |
nlp = pipeline("sentiment-analysis", model=model_name)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def analyze_text(text):
|
| 8 |
result = nlp(text)[0]
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
demo = gr.Interface(
|
| 12 |
fn=analyze_text,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
model_name = "ZombitX64/Thai-sentiment-e5"
|
| 5 |
nlp = pipeline("sentiment-analysis", model=model_name)
|
| 6 |
|
| 7 |
+
label_map = {
|
| 8 |
+
"LABEL_0": 0,
|
| 9 |
+
"LABEL_1": 1,
|
| 10 |
+
"LABEL_2": 2
|
| 11 |
+
}
|
| 12 |
+
label_name_map = {
|
| 13 |
+
"LABEL_0": "negative",
|
| 14 |
+
"LABEL_1": "neutral",
|
| 15 |
+
"LABEL_2": "positive"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
def analyze_text(text):
|
| 19 |
result = nlp(text)[0]
|
| 20 |
+
label = result['label']
|
| 21 |
+
score = result['score']
|
| 22 |
+
code = label_map.get(label, -1)
|
| 23 |
+
label_name = label_name_map.get(label, label)
|
| 24 |
+
return f"ผลวิเคราะห์: {label_name} (รหัส: {code}) ความมั่นใจ {score:.2f}"
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=analyze_text,
|