Pendrokar commited on
Commit
431fb1c
Β·
1 Parent(s): 5f9b200

DeepMoji plugin: per-model amplifiers; decreased sadness pacing adjustment

Browse files
resources/app/plugins/deepmoji_plugin/ccby_amplifiers.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ model,amplifier_value
2
+ ccby_nvidia_hifi_92_F,1.0
resources/app/plugins/deepmoji_plugin/other_amplifiers.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ model,amplifier_value
2
+ x_ex02,1.0
3
+ x_ex04,1.0
resources/app/plugins/deepmoji_plugin/sentiment.py CHANGED
@@ -34,12 +34,23 @@ last_em_happy = float(0)
34
  last_em_sad = float(0)
35
  last_em_surprise = float(0)
36
 
37
- def scoreText(text):
38
- return text
39
  from plugins.deepmoji_plugin.xvasynth_torchmoji import scoreText
40
  import csv
41
 
 
 
 
 
 
 
 
 
 
 
 
42
  def setup(data=None):
 
 
43
  logger.log(f'Setting up plugin. App version: {data["appVersion"]} | CPU only: {data["isCPUonly"]} | Development mode: {data["isDev"]}')
44
  # Show test emoji in console; can crash due to encoding issues
45
  try:
@@ -47,11 +58,20 @@ def setup(data=None):
47
  except:
48
  pass
49
 
 
 
 
 
 
 
 
 
50
  def pre_load_model(data=None):
51
  # reset last em values
52
  global last_em_angry, last_em_happy, last_em_sad, last_em_surprise,\
53
  isBatch, isXVAPitch, isEnglish, prev_sentence,\
54
- plugin_settings, configparser, emoji_count
 
55
 
56
  # reload settings from INI
57
  config = configparser.ConfigParser()
@@ -71,6 +91,19 @@ def pre_load_model(data=None):
71
  last_em_sad = float(0)
72
  last_em_surprise = float(0)
73
  logger.log("last_em reset")
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  def fetch_text(data=None):
76
  global plugin_settings, emoji_count, text_scores, scoreText, isXVAPitch, isEnglish, prev_sentence
@@ -86,11 +119,8 @@ def fetch_text(data=None):
86
  pass
87
 
88
  if (
89
- (
90
- plugin_settings["load_deepmoji_model"]=="false"
91
- or plugin_settings["load_deepmoji_model"]==False
92
- )
93
- and data["pluginsContext"]["mantella_settings"]["run_model"]==False
94
  ):
95
  logger.log("DeepMoji model skipped")
96
  return
@@ -171,7 +201,8 @@ def fetch_text_batch(data=None):
171
  def adjust_values(data=None):
172
  global root_path, os, csv, example_helper,\
173
  isBatch, isXVAPitch, isEnglish, logger, emoji_count, text_scores, plugin_settings,\
174
- prev_sentence, last_em_angry, last_em_happy, last_em_sad, last_em_surprise
 
175
 
176
  if (
177
  isBatch
@@ -227,7 +258,6 @@ def adjust_values(data=None):
227
  em_angry_max = 0.6
228
  try:
229
  em_angry += float(data["pluginsContext"]["mantella_settings"]["emAngry"]) * 100
230
- em_angry_max = 1
231
  except:
232
  pass
233
  try:
@@ -243,26 +273,19 @@ def adjust_values(data=None):
243
  except:
244
  pass
245
 
246
- # HF
247
- if (len(text_scores) > 1):
248
- # top_em highest wins all
249
- top_em = max(
250
- em_angry,
251
- em_happy,
252
- em_sad
253
- )
254
- em_angry = em_angry if (em_angry == top_em) else 0
255
- em_happy = em_happy if (em_happy == top_em) else 0
256
- # amplified sadness ratio
257
- em_sad = (em_sad * 3) if (em_sad == top_em) else 0
258
-
259
- # amplifier
260
- ratio = float(plugin_settings['amplifier_ratio'])
261
- else:
262
- ratio = 1.0
263
- em_emotion_max = 1
264
- em_angry_max = 1
265
-
266
  logger.log(f'Amplifier ratio: {ratio}')
267
  hasExcMark = False
268
  if ('!!!' in text_scores[0]):
@@ -287,11 +310,6 @@ def adjust_values(data=None):
287
  logger.log(f'! Ratio: {ratio}')
288
  hasExcMark = True
289
 
290
- # HF
291
- if (len(text_scores) <= 1):
292
- em_angry_max = 1
293
- ratio = 1
294
-
295
  # final values
296
  em_angry = min(em_angry_max, em_angry / 100 * ratio) if em_angry > 0 else 0
297
  em_happy = min(em_emotion_max, em_happy / 100 * ratio) if em_happy > 0 else 0
@@ -370,10 +388,10 @@ def adjust_values(data=None):
370
  data["hasDataChanged"] = True
371
 
372
  # slower the speech if above threshold
373
- if (em_sad > 0.2):
374
  try:
375
- data["pace"] *= (1 + em_sad / 3)
376
- logger.log(f"Adjusting pacing: {1 + em_sad / 3}")
377
  except:
378
  pass
379
 
 
34
  last_em_sad = float(0)
35
  last_em_surprise = float(0)
36
 
 
 
37
  from plugins.deepmoji_plugin.xvasynth_torchmoji import scoreText
38
  import csv
39
 
40
+ game_list = [
41
+ 'skyrim',
42
+ 'fallout4',
43
+ 'other',
44
+ 'ccby',
45
+ ]
46
+ # amplifier values for certain models
47
+ model_amplifiers = {
48
+ }
49
+ amplifier_value = None
50
+
51
  def setup(data=None):
52
+ global game_list, model_amplifiers
53
+
54
  logger.log(f'Setting up plugin. App version: {data["appVersion"]} | CPU only: {data["isCPUonly"]} | Development mode: {data["isDev"]}')
55
  # Show test emoji in console; can crash due to encoding issues
56
  try:
 
58
  except:
59
  pass
60
 
61
+ # for game in game_list:
62
+ # with open(f'{root_path}/plugins/deepmoji_plugin/{game}_amplifiers.csv', encoding='utf-8') as csvfile:
63
+ # reader = csv.DictReader(csvfile)
64
+ # for row in reader:
65
+ # model_amplifiers[row['model']] = float(row['amplifier_value'])
66
+ # print(model_amplifiers)
67
+ # forgotten right after
68
+
69
  def pre_load_model(data=None):
70
  # reset last em values
71
  global last_em_angry, last_em_happy, last_em_sad, last_em_surprise,\
72
  isBatch, isXVAPitch, isEnglish, prev_sentence,\
73
+ plugin_settings, configparser, emoji_count,\
74
+ model_amplifiers, amplifier_value
75
 
76
  # reload settings from INI
77
  config = configparser.ConfigParser()
 
91
  last_em_sad = float(0)
92
  last_em_surprise = float(0)
93
  logger.log("last_em reset")
94
+ amplifier_value = None
95
+ try:
96
+ for game in game_list:
97
+ with open(f'{root_path}/plugins/deepmoji_plugin/{game}_amplifiers.csv', encoding='utf-8') as csvfile:
98
+ reader = csv.DictReader(csvfile)
99
+ for row in reader:
100
+ model_amplifiers[row['model']] = float(row['amplifier_value'])
101
+
102
+ model_name = data['model'][(data['model'].rindex('/') + 1):]
103
+ amplifier_value = model_amplifiers[model_name]
104
+ logger.log(f"Voice model amplifier value: {amplifier_value}")
105
+ except:
106
+ pass
107
 
108
  def fetch_text(data=None):
109
  global plugin_settings, emoji_count, text_scores, scoreText, isXVAPitch, isEnglish, prev_sentence
 
119
  pass
120
 
121
  if (
122
+ plugin_settings["load_deepmoji_model"]=="false"
123
+ or plugin_settings["load_deepmoji_model"]==False
 
 
 
124
  ):
125
  logger.log("DeepMoji model skipped")
126
  return
 
201
  def adjust_values(data=None):
202
  global root_path, os, csv, example_helper,\
203
  isBatch, isXVAPitch, isEnglish, logger, emoji_count, text_scores, plugin_settings,\
204
+ prev_sentence, last_em_angry, last_em_happy, last_em_sad, last_em_surprise,\
205
+ amplifier_value
206
 
207
  if (
208
  isBatch
 
258
  em_angry_max = 0.6
259
  try:
260
  em_angry += float(data["pluginsContext"]["mantella_settings"]["emAngry"]) * 100
 
261
  except:
262
  pass
263
  try:
 
273
  except:
274
  pass
275
 
276
+ # top_em highest wins all
277
+ top_em = max(
278
+ em_angry,
279
+ em_happy,
280
+ em_sad
281
+ )
282
+ em_angry = em_angry if (em_angry == top_em) else 0
283
+ em_happy = em_happy if (em_happy == top_em) else 0
284
+ # amplified sadness ratio
285
+ em_sad = (em_sad * 3) if (em_sad == top_em) else 0
286
+
287
+ # amplifier
288
+ ratio = float(plugin_settings['amplifier_ratio']) if not amplifier_value else amplifier_value
 
 
 
 
 
 
 
289
  logger.log(f'Amplifier ratio: {ratio}')
290
  hasExcMark = False
291
  if ('!!!' in text_scores[0]):
 
310
  logger.log(f'! Ratio: {ratio}')
311
  hasExcMark = True
312
 
 
 
 
 
 
313
  # final values
314
  em_angry = min(em_angry_max, em_angry / 100 * ratio) if em_angry > 0 else 0
315
  em_happy = min(em_emotion_max, em_happy / 100 * ratio) if em_happy > 0 else 0
 
388
  data["hasDataChanged"] = True
389
 
390
  # slower the speech if above threshold
391
+ if (em_sad > 0.25):
392
  try:
393
+ data["pace"] *= (1 + em_sad / 4)
394
+ logger.log(f"Adjusting pacing: {1 + em_sad / 4}")
395
  except:
396
  pass
397