Spaces:
Sleeping
Sleeping
Update emotion_predictor.py
Browse files- emotion_predictor.py +16 -2
emotion_predictor.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import re
|
| 2 |
import math
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import matplotlib.font_manager as fm
|
| 5 |
import torch
|
|
@@ -10,6 +11,7 @@ from sklearn.linear_model import LinearRegression
|
|
| 10 |
from collections import defaultdict
|
| 11 |
import base64
|
| 12 |
from io import BytesIO
|
|
|
|
| 13 |
|
| 14 |
# ======================
|
| 15 |
# βοΈ ν°νΈ μ€μ
|
|
@@ -159,7 +161,19 @@ def predict_and_plot(raw_text):
|
|
| 159 |
else:
|
| 160 |
html_output += "<p>β οΈ μκ°νν μ μλ κ°μ μ΄ μμ΅λλ€.</p><hr/>"
|
| 161 |
|
| 162 |
-
|
|
|
|
| 163 |
"html": html_output,
|
| 164 |
"utterance_emotion_log": utterance_emotion_log
|
| 165 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
import math
|
| 3 |
+
import json
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import matplotlib.font_manager as fm
|
| 6 |
import torch
|
|
|
|
| 11 |
from collections import defaultdict
|
| 12 |
import base64
|
| 13 |
from io import BytesIO
|
| 14 |
+
from IPython.display import HTML, display # Jupyter/Colab HTML νμμ©
|
| 15 |
|
| 16 |
# ======================
|
| 17 |
# βοΈ ν°νΈ μ€μ
|
|
|
|
| 161 |
else:
|
| 162 |
html_output += "<p>β οΈ μκ°νν μ μλ κ°μ μ΄ μμ΅λλ€.</p><hr/>"
|
| 163 |
|
| 164 |
+
# === κ²°κ³Ό μ 리 ===
|
| 165 |
+
result = {
|
| 166 |
"html": html_output,
|
| 167 |
"utterance_emotion_log": utterance_emotion_log
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
# HTML μκ°ν νκ²½ (μ: Jupyter, Colab)μμλ λ°λ‘ λ λλ§
|
| 171 |
+
try:
|
| 172 |
+
display(HTML(result["html"]))
|
| 173 |
+
except:
|
| 174 |
+
pass # μΉμλ²λ λΉλ λ νκ²½μμλ 무μ
|
| 175 |
+
|
| 176 |
+
# ꡬ쑰νλ κ°μ λ‘κ·Έλ₯Ό 보기 μ’κ² μΆλ ₯ (or APIμμλ JSON μ§λ ¬ν κ°λ₯)
|
| 177 |
+
print(json.dumps(result["utterance_emotion_log"], ensure_ascii=False, indent=2))
|
| 178 |
+
|
| 179 |
+
return result
|