Kvikontent commited on
Commit
684979f
·
1 Parent(s): c6a567c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -1,29 +1,26 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
3
 
4
- # Load the model and tokenizer
5
- model_name = "facebook/wav2vec2-large-xlsr-53"
6
- tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
- # Define the Gradio interface
10
  def text_to_speech(text):
11
- # Tokenize the input text
12
- inputs = tokenizer(text, return_tensors="pt", padding=True)
 
13
 
14
- # Generate speech from the input text using the loaded model
15
- with torch.no_grad():
16
- outputs = model.generate(**inputs)
17
-
18
- # Convert the generated speech tensor to audio format
19
- speech = gradio.inputs.Audio(outputs[0].numpy().tolist(), type='torch')
 
 
 
 
 
 
 
20
 
21
- return speech
22
-
23
- # Create the Gradio interface
24
- iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio",
25
- title="Text-to-Speech App",
26
- description="Enter text to hear the speech")
27
-
28
- # Launch the Gradio interface
29
- iface.launch()
 
1
  import gradio as gr
2
+ from IPython.display import Audio
3
+ from transformers import pipeline
4
 
5
+ pipe = pipeline("text-to-speech", model="suno/bark-small")
 
 
 
6
 
 
7
  def text_to_speech(text):
8
+ output = pipe(text)
9
+ audio = Audio(output[0]["audio"], rate=output[0]["sampling_rate"])
10
+ return audio
11
 
12
+ iface = gr.Interface(
13
+ fn=text_to_speech,
14
+ inputs="text",
15
+ outputs="audio",
16
+ title="Text-to-Speech",
17
+ description="Convert text to speech using Hugging Face's TTS model",
18
+ examples=[
19
+ ["Hello, how are you?"],
20
+ ["Could you please repeat that?"],
21
+ ["This is a test."],
22
+ ],
23
+ article="https://huggingface.co/models",
24
+ )
25
 
26
+ iface.launch()