Neomindapp commited on
Commit
a1f77c1
·
verified ·
1 Parent(s): f9d0c83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -1,31 +1,30 @@
1
  import gradio as gr
2
  import torch
3
- from your_model_module import YourTTSModel, YourTTSProcessor # Replace with your actual imports
 
4
 
5
- # Load the model and processor
6
- model = YourTTSModel.from_pretrained("config.json")
7
- model.load_state_dict(torch.load("best_model.pth"))
8
- model.eval() # Set the model to evaluation mode
9
 
10
- processor = YourTTSProcessor.from_pretrained("config.json")
 
11
 
12
  def generate_speech(text):
13
- # Process the input text
14
- inputs = processor(text, return_tensors="pt")
15
-
16
  # Generate speech using the model
17
- with torch.no_grad(): # No need to compute gradients
18
- outputs = model.generate(**inputs)
19
-
20
- # Process the output to an audio format
21
- audio = outputs.squeeze().numpy() # Adjust this based on how your model outputs data
22
- return audio
 
23
 
24
  # Define the Gradio interface
25
  iface = gr.Interface(
26
  fn=generate_speech,
27
  inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
28
- outputs=gr.Audio(type="numpy"),
29
  title="Text-to-Speech with Coqui TTS",
30
  description="Generate speech from text using a custom Coqui TTS model."
31
  )
 
1
  import gradio as gr
2
  import torch
3
+ from coqui_tts import TTS
4
+ from coqui_tts.utils import audio
5
 
6
+ # Load the Coqui TTS model and configuration
7
+ model_path = "best_model.pth" # Directory where the model is saved
8
+ config_path = "config.json"
 
9
 
10
+ # Initialize TTS with your model and configuration
11
+ tts = TTS(model_path=model_path, config_path=config_path)
12
 
13
  def generate_speech(text):
 
 
 
14
  # Generate speech using the model
15
+ audio_path = tts.tts_to_file(text, "output.wav")
16
+
17
+ # Load the generated audio file
18
+ with open(audio_path, "rb") as f:
19
+ audio_data = f.read()
20
+
21
+ return audio_data
22
 
23
  # Define the Gradio interface
24
  iface = gr.Interface(
25
  fn=generate_speech,
26
  inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
27
+ outputs=gr.Audio(type="file"),
28
  title="Text-to-Speech with Coqui TTS",
29
  description="Generate speech from text using a custom Coqui TTS model."
30
  )