Spaces:
Sleeping
Sleeping
Commit
•
e6b09cb
1
Parent(s):
62230e1
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,31 @@
|
|
|
|
1 |
from transformers import VitsModel, AutoTokenizer
|
2 |
import torch
|
3 |
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
from transformers import VitsModel, AutoTokenizer
|
3 |
import torch
|
4 |
|
5 |
+
# Title and Description
|
6 |
+
st.title("Text-to-Speech with VitsModel")
|
7 |
+
st.write("Enter some English text, and I'll generate audio for you!")
|
8 |
|
9 |
+
# Load Model and Tokenizer
|
10 |
+
@st.cache_resource # Cache the model for efficiency
|
11 |
+
def load_tts_model():
|
12 |
+
model = VitsModel.from_pretrained("facebook/mms-tts-eng")
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
14 |
+
return model, tokenizer
|
15 |
|
16 |
+
model, tokenizer = load_tts_model()
|
17 |
+
|
18 |
+
# User Input
|
19 |
+
user_text = st.text_input("Enter your text here:")
|
20 |
+
|
21 |
+
# Generate Audio on Button Click
|
22 |
+
if st.button("Generate Speech"):
|
23 |
+
if not user_text:
|
24 |
+
st.warning("Please enter some text.")
|
25 |
+
else:
|
26 |
+
inputs = tokenizer(user_text, return_tensors="pt")
|
27 |
+
with torch.no_grad():
|
28 |
+
output = model(**inputs).waveform
|
29 |
+
|
30 |
+
# Play the Audio Directly
|
31 |
+
st.audio(output[0].numpy())
|