Anton Forsman commited on
Commit
9078865
·
1 Parent(s): d4c3b55

Uploaded model demo

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -1,4 +1,32 @@
 
 
1
  import streamlit as st
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import numpy as np
3
  import streamlit as st
4
+ from GPTTTS import GPTTTSTokenizer, GPTTTS
5
+ import torch
6
+ import torchaudio
7
+ import tempfile
8
 
9
+ # Load your GPTTTSTokenizer
10
+ tokenizer = GPTTTSTokenizer()
11
+
12
+ # Load the GPT-TTS model
13
+ model = GPTTTS()
14
+
15
+ st.title("GPT-TTS Demo")
16
+ user_text = st.text_input("Enter text:")
17
+
18
+ if user_text:
19
+ # Tokenize the input text
20
+ inputs = tokenizer(user_text)["input_ids"]
21
+
22
+ with st.spinner("Generating audio..."):
23
+ # Generate the audio tensor
24
+ with torch.no_grad():
25
+ audio = model(inputs)
26
+
27
+ # Save the audio tensor to a temporary file
28
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_wav:
29
+ torchaudio.save(tmp_wav.name, audio, sample_rate=model.sample_rate)
30
+
31
+ # Load the temporary file and play the audio
32
+ st.audio(tmp_wav.read(), format="audio/wav")