Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,12 @@
|
|
| 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 |
-
"LABEL_3": 3 # เพิ่ม label_3 ตามจริง
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
label_name_map = {
|
| 15 |
-
"LABEL_0": "negative",
|
| 16 |
-
"LABEL_1": "neutral",
|
| 17 |
-
"LABEL_2": "positive",
|
| 18 |
-
"LABEL_3": "mixed" # หรือคำอื่นที่ตรงกับความหมาย
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
def analyze_text(text):
|
| 22 |
result = nlp(text)[0]
|
| 23 |
-
|
| 24 |
-
score = result['score']
|
| 25 |
-
code = label_map.get(label, -1)
|
| 26 |
-
label_name = label_name_map.get(label, label)
|
| 27 |
-
return f"ผลวิเคราะห์: {label_name} (รหัส: {code}) ความมั่นใจ {score:.3f}"
|
| 28 |
-
|
| 29 |
|
| 30 |
demo = gr.Interface(
|
| 31 |
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 |
def analyze_text(text):
|
| 8 |
result = nlp(text)[0]
|
| 9 |
+
return f"ผลวิเคราะห์: {result['label']} (ความมั่นใจ {result['score']:.2f})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
demo = gr.Interface(
|
| 12 |
fn=analyze_text,
|