Spaces:
Paused
Paused
Sumedh commited on
Commit ·
22b006c
1
Parent(s): cb89656
Claude: fix indic-parler-tts description tokenizer loading + pin parler-tts to Dec 2024 commit
Browse files- Load description tokenizer from model.config.text_encoder._name_or_path
(per official AI4Bharat example) instead of a nonexistent
subfolder='description_tokenizer', which caused 'Unrecognized model'
- Pass attention masks to generate() for cleaner output
- Pin parler-tts to commit d108732 (Dec 2024) to match indic-parler-tts
- app.py +12 -4
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -121,9 +121,12 @@ def _get_indic_tts():
|
|
| 121 |
_indic_tts_model = ParlerTTSForConditionalGeneration.from_pretrained(
|
| 122 |
"ai4bharat/indic-parler-tts"
|
| 123 |
).to(device)
|
|
|
|
| 124 |
_indic_tts_tokenizer = AutoTokenizer.from_pretrained("ai4bharat/indic-parler-tts")
|
|
|
|
|
|
|
| 125 |
_indic_desc_tokenizer = AutoTokenizer.from_pretrained(
|
| 126 |
-
|
| 127 |
)
|
| 128 |
print(f"[IndicTTS] Model ready on {device}.", flush=True)
|
| 129 |
return _indic_tts_model, _indic_tts_tokenizer, _indic_desc_tokenizer
|
|
@@ -145,11 +148,16 @@ def kokoro_tts_to_wav(text: str, speed: float = 1.0):
|
|
| 145 |
model, tokenizer, desc_tokenizer = _get_indic_tts()
|
| 146 |
device = model.device
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
with torch.no_grad():
|
| 152 |
-
generation = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
audio_np = generation.cpu().numpy().squeeze()
|
| 155 |
sample_rate = model.config.sampling_rate
|
|
|
|
| 121 |
_indic_tts_model = ParlerTTSForConditionalGeneration.from_pretrained(
|
| 122 |
"ai4bharat/indic-parler-tts"
|
| 123 |
).to(device)
|
| 124 |
+
# Prompt tokenizer = the model repo's tokenizer (tokenizes the text to speak)
|
| 125 |
_indic_tts_tokenizer = AutoTokenizer.from_pretrained("ai4bharat/indic-parler-tts")
|
| 126 |
+
# Description tokenizer = the text-encoder's tokenizer (tokenizes the voice description).
|
| 127 |
+
# Loaded from text_encoder._name_or_path per the official AI4Bharat example — NOT a subfolder.
|
| 128 |
_indic_desc_tokenizer = AutoTokenizer.from_pretrained(
|
| 129 |
+
_indic_tts_model.config.text_encoder._name_or_path
|
| 130 |
)
|
| 131 |
print(f"[IndicTTS] Model ready on {device}.", flush=True)
|
| 132 |
return _indic_tts_model, _indic_tts_tokenizer, _indic_desc_tokenizer
|
|
|
|
| 148 |
model, tokenizer, desc_tokenizer = _get_indic_tts()
|
| 149 |
device = model.device
|
| 150 |
|
| 151 |
+
desc_inputs = desc_tokenizer(INDIC_TTS_DESCRIPTION, return_tensors="pt").to(device)
|
| 152 |
+
prompt_inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 153 |
|
| 154 |
with torch.no_grad():
|
| 155 |
+
generation = model.generate(
|
| 156 |
+
input_ids=desc_inputs.input_ids,
|
| 157 |
+
attention_mask=desc_inputs.attention_mask,
|
| 158 |
+
prompt_input_ids=prompt_inputs.input_ids,
|
| 159 |
+
prompt_attention_mask=prompt_inputs.attention_mask,
|
| 160 |
+
)
|
| 161 |
|
| 162 |
audio_np = generation.cpu().numpy().squeeze()
|
| 163 |
sample_rate = model.config.sampling_rate
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
--extra-index-url https://download.pytorch.org/whl/cu121
|
| 2 |
torch==2.3.1+cu121
|
| 3 |
torchaudio==2.3.1+cu121
|
| 4 |
-
git+https://github.com/huggingface/parler-tts.git
|
| 5 |
transformers==4.46.1
|
| 6 |
hf_transfer
|
| 7 |
huggingface_hub>=0.23.2,<1.0
|
|
|
|
| 1 |
--extra-index-url https://download.pytorch.org/whl/cu121
|
| 2 |
torch==2.3.1+cu121
|
| 3 |
torchaudio==2.3.1+cu121
|
| 4 |
+
git+https://github.com/huggingface/parler-tts.git@d108732cd57788ec86bc857d99a6cabd66663d68
|
| 5 |
transformers==4.46.1
|
| 6 |
hf_transfer
|
| 7 |
huggingface_hub>=0.23.2,<1.0
|