Update app.py
Browse files
app.py
CHANGED
@@ -3,17 +3,17 @@ import torch
|
|
3 |
from transformers import VitsModel, VitsTokenizer
|
4 |
|
5 |
# --- 1. Load Model and Tokenizer ---
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
model = VitsModel.from_pretrained(
|
10 |
-
tokenizer = VitsTokenizer.from_pretrained(
|
11 |
print("Model and tokenizer loaded successfully.")
|
12 |
|
13 |
# --- 2. Define the Speech Synthesis Function ---
|
14 |
def synthesize_speech(text):
|
15 |
"""
|
16 |
-
Converts text to speech using the
|
17 |
"""
|
18 |
# Tokenize the input text. The `return_tensors="pt"` part formats it for PyTorch.
|
19 |
inputs = tokenizer(text, return_tensors="pt")
|
@@ -39,14 +39,14 @@ demo = gr.Interface(
|
|
39 |
inputs=gr.Textbox(
|
40 |
label="Text to Synthesize",
|
41 |
info="Enter the text you want to convert to speech.",
|
42 |
-
value="Hello, this is a demonstration of the
|
43 |
),
|
44 |
outputs=gr.Audio(
|
45 |
label="Synthesized Audio",
|
46 |
type="numpy" # The function returns a NumPy array
|
47 |
),
|
48 |
-
title="🗣️
|
49 |
-
description="A
|
50 |
examples=[
|
51 |
["The quick brown fox jumps over the lazy dog."],
|
52 |
["To be, or not to be, that is the question."],
|
|
|
3 |
from transformers import VitsModel, VitsTokenizer
|
4 |
|
5 |
# --- 1. Load Model and Tokenizer ---
|
6 |
+
# NOTE: Switched to a compatible model that has the correct file structure.
|
7 |
+
print("Loading facebook/mms-tts-eng model and tokenizer...")
|
8 |
+
model_id = "facebook/mms-tts-eng"
|
9 |
+
model = VitsModel.from_pretrained(model_id)
|
10 |
+
tokenizer = VitsTokenizer.from_pretrained(model_id)
|
11 |
print("Model and tokenizer loaded successfully.")
|
12 |
|
13 |
# --- 2. Define the Speech Synthesis Function ---
|
14 |
def synthesize_speech(text):
|
15 |
"""
|
16 |
+
Converts text to speech using the selected TTS model.
|
17 |
"""
|
18 |
# Tokenize the input text. The `return_tensors="pt"` part formats it for PyTorch.
|
19 |
inputs = tokenizer(text, return_tensors="pt")
|
|
|
39 |
inputs=gr.Textbox(
|
40 |
label="Text to Synthesize",
|
41 |
info="Enter the text you want to convert to speech.",
|
42 |
+
value="Hello, this is a demonstration of the Facebook MMS text to speech model."
|
43 |
),
|
44 |
outputs=gr.Audio(
|
45 |
label="Synthesized Audio",
|
46 |
type="numpy" # The function returns a NumPy array
|
47 |
),
|
48 |
+
title="🗣️ MMS Text-to-Speech (English)",
|
49 |
+
description="A Gradio app to run the `facebook/mms-tts-eng` model for text-to-speech conversion.",
|
50 |
examples=[
|
51 |
["The quick brown fox jumps over the lazy dog."],
|
52 |
["To be, or not to be, that is the question."],
|