Kvikontent commited on
Commit
78f9221
·
1 Parent(s): 4151c7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,13 +1,21 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load the text-to-speech pipeline from Hugging Face
5
- pipe = pipeline("text2speech", model="suno/bark-small")
 
 
6
 
7
  # Define the Gradio interface
8
  def text_to_speech(text):
9
- # Generate speech from the input text using the loaded pipeline
10
- speech = pipe(text)[0]["speech"]
 
 
 
 
 
 
11
 
12
  return speech
13
 
@@ -17,4 +25,4 @@ iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio",
17
  description="Enter text to hear the speech")
18
 
19
  # Launch the Gradio interface
20
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
+ # Load the model and tokenizer
5
+ model_name = "suno/bark-small"
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.encode(text, return_tensors="pt")
13
+
14
+ # Generate speech from the input text using the loaded model
15
+ outputs = model.generate(inputs)
16
+
17
+ # Convert the generated speech tensor to audio format
18
+ speech = gradio.inputs.Audio(outputs)
19
 
20
  return speech
21
 
 
25
  description="Enter text to hear the speech")
26
 
27
  # Launch the Gradio interface
28
+ iface.launch()