Spaces:
Sleeping
Sleeping
Commit
·
9bbd4d5
1
Parent(s):
3b364be
Upload 2 files
Browse files- app.py +19 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ใช้โมเดลสำหรับ Classification อารมณ์ในข้อความ
|
2 |
+
emotion_model_name = "alexandrainst/da-emotion-classification-base"
|
3 |
+
emotion_tokenizer = AutoTokenizer.from_pretrained(emotion_model_name)
|
4 |
+
emotion_model = AutoModelForSequenceClassification.from_pretrained(emotion_model_name)
|
5 |
+
|
6 |
+
# ตัวอย่างการใช้โมเดลสำหรับ Classification อารมณ์ในข้อความ
|
7 |
+
text = "I am feeling happy and excited today."
|
8 |
+
inputs = emotion_tokenizer(text, return_tensors="pt")
|
9 |
+
outputs = emotion_model(**inputs)
|
10 |
+
logits = outputs.logits
|
11 |
+
|
12 |
+
# คำนวณคะแนนความน่าจะเป็นของแต่ละอารมณ์
|
13 |
+
probabilities = logits.softmax(dim=1)
|
14 |
+
|
15 |
+
# หาอารมณ์ที่มีความน่าจะเป็นสูงสุด
|
16 |
+
predicted_emotion = torch.argmax(probabilities, dim=1).item()
|
17 |
+
|
18 |
+
# แสดงอารมณ์ที่ทำนาย
|
19 |
+
print(f"Predicted Emotion: {predicted_emotion}")
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
altair<5
|