leewatson commited on
Commit
95ebf2a
Β·
verified Β·
1 Parent(s): 5cf987e

Update emotion_predictor.py

Browse files
Files changed (1) hide show
  1. 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
- return {
 
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