Update app.py
Browse files
app.py
CHANGED
|
@@ -5,33 +5,33 @@ import torchaudio
|
|
| 5 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
|
| 6 |
from transformers.models.speecht5 import SpeechT5HifiGan
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
| 11 |
-
|
| 12 |
-
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
-
# model = model.to(device)
|
| 14 |
-
# vocoder = vocoder.to(device)
|
| 15 |
-
|
| 16 |
-
# speaker_embedding = torch.zeros(1, 512).to(device)
|
| 17 |
-
|
| 18 |
-
# Load model and processor
|
| 19 |
-
processor = SpeechT5Processor.from_pretrained("nambn0321/TTS_with_T5")
|
| 20 |
-
model = SpeechT5ForTextToSpeech.from_pretrained(
|
| 21 |
-
"nambn0321/TTS_with_T5",
|
| 22 |
-
use_safetensors=True,
|
| 23 |
-
trust_remote_code=True
|
| 24 |
-
)
|
| 25 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
| 26 |
|
| 27 |
-
# Move to CUDA if available
|
| 28 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 29 |
model = model.to(device)
|
| 30 |
vocoder = vocoder.to(device)
|
| 31 |
|
| 32 |
-
# Dummy speaker embedding (or load your real one here)
|
| 33 |
speaker_embedding = torch.zeros(1, 512).to(device)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def tts_generate(text):
|
| 36 |
print(f"📝 Input text: {text}")
|
| 37 |
try:
|
|
|
|
| 5 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
|
| 6 |
from transformers.models.speecht5 import SpeechT5HifiGan
|
| 7 |
|
| 8 |
+
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
| 9 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
| 11 |
|
|
|
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
model = model.to(device)
|
| 14 |
vocoder = vocoder.to(device)
|
| 15 |
|
|
|
|
| 16 |
speaker_embedding = torch.zeros(1, 512).to(device)
|
| 17 |
|
| 18 |
+
# Load model and processor
|
| 19 |
+
# processor = SpeechT5Processor.from_pretrained("nambn0321/TTS_with_T5")
|
| 20 |
+
# model = SpeechT5ForTextToSpeech.from_pretrained(
|
| 21 |
+
# "nambn0321/TTS_with_T5",
|
| 22 |
+
# use_safetensors=True,
|
| 23 |
+
# trust_remote_code=True
|
| 24 |
+
# )
|
| 25 |
+
# vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
| 26 |
+
|
| 27 |
+
# # Move to CUDA if available
|
| 28 |
+
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 29 |
+
# model = model.to(device)
|
| 30 |
+
# vocoder = vocoder.to(device)
|
| 31 |
+
|
| 32 |
+
# # Dummy speaker embedding (or load your real one here)
|
| 33 |
+
# speaker_embedding = torch.zeros(1, 512).to(device)
|
| 34 |
+
|
| 35 |
def tts_generate(text):
|
| 36 |
print(f"📝 Input text: {text}")
|
| 37 |
try:
|