Skip to content
Python

added missing requirement, refined multi emotions

DeepBeepMeep22d55bf583e8
diff --git a/models/TTS/index_tts2/infer_v2.py b/models/TTS/index_tts2/infer_v2.py
index a01641c..62daf89 100644
--- a/models/TTS/index_tts2/infer_v2.py
+++ b/models/TTS/index_tts2/infer_v2.py
@@ -534,7 +534,7 @@ class IndexTTS2:
key_preview = re.sub(r"\s+", " ", key).strip()
if len(key_preview) > 160:
key_preview = key_preview[:157] + "..."
- print(f">> detected mixed emotion tags: '{key_preview}' -> {keyword_emotions}")
+ print(f">> detected emotion from keywords: '{key_preview}' -> {keyword_emotions}")
return list(emo_vector)
emo_dict = self.qwen_emo.inference(key, log_if_default=log_if_default)
emo_vector = list(emo_dict.values())
@@ -1420,25 +1420,43 @@ class QwenEmotion:
raw = re.sub(r"[\[\]]", " ", str(text_input or "")).strip().lower()
if len(raw) == 0:
return None
- if "," not in raw and "," not in raw:
+ chunks = [chunk.strip() for chunk in re.split(r"[,,;/|+]+", raw) if chunk.strip()]
+ if len(chunks) == 0:
return None
- chunks = [chunk.strip() for chunk in re.split(r"[,,]+", raw) if chunk.strip()]
- if len(chunks) <= 1:
- return None
- parsed_keys = []
+ explicit_weights = {}
+ unweighted_keys = []
for chunk in chunks:
normalized_chunk = re.sub(r"\s+", " ", chunk).strip()
- parsed_key = self._keyword_aliases.get(normalized_chunk) or self._keyword_aliases.get(normalized_chunk.replace(" ", ""))
+ parsed_key = None
+ parsed_value = 1.0
+ weighted_match = re.match(r"^(.+?)\s*[:=]\s*([-+]?\d*\.?\d+)\s*$", normalized_chunk)
+ if weighted_match is not None:
+ alias = re.sub(r"\s+", " ", weighted_match.group(1)).strip()
+ parsed_key = self._keyword_aliases.get(alias) or self._keyword_aliases.get(alias.replace(" ", ""))
+ try:
+ parsed_value = float(weighted_match.group(2))
+ except Exception:
+ parsed_value = 1.0
+ else:
+ parsed_key = self._keyword_aliases.get(normalized_chunk) or self._keyword_aliases.get(normalized_chunk.replace(" ", ""))
if parsed_key is None:
return None
- parsed_keys.append(parsed_key)
- unique_keys = list(dict.fromkeys(parsed_keys))
- if len(unique_keys) <= 1:
- return None
- split_value = 1.0 / float(len(unique_keys))
+ if weighted_match is not None:
+ explicit_weights[parsed_key] = max(float(explicit_weights.get(parsed_key, 0.0)), self.clamp_score(parsed_value))
+ if parsed_key in unweighted_keys:
+ unweighted_keys.remove(parsed_key)
+ elif parsed_key not in explicit_weights and parsed_key not in unweighted_keys:
+ unweighted_keys.append(parsed_key)
values = {key: 0.0 for key in self.emotion_keys}
- for one_key in unique_keys:
- values[one_key] = split_value
+ for key, value in explicit_weights.items():
+ values[key] = float(value)
+ remaining = 1.0 - sum(float(v) for v in explicit_weights.values())
+ if len(unweighted_keys) > 0:
+ shared = (remaining / float(len(unweighted_keys))) if remaining > 0 else 0.0
+ for key in unweighted_keys:
+ values[key] = float(shared)
+ if all(v <= 0.0 for v in values.values()):
+ values["calm"] = 1.0
return values
def release_cuda_graph(self):
diff --git a/requirements.txt b/requirements.txt
index 6b63a7d..f7ba1c3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -82,6 +82,7 @@ gitdb==4.0.12
gitpython==3.1.45
stringzilla==4.0.14
xxhash
+munch
# Optional / commented out
# transformers==4.46.3 # for llamallava pre-patch