ayush2607 commited on
Commit
fc172c7
·
verified ·
1 Parent(s): 5104349

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -22,18 +22,21 @@ def quantize_model(model):
22
  )
23
  return quantized_model
24
 
25
- model = quantize_model(model)
26
  vocoder = quantize_model(vocoder)
27
 
28
- # JIT compile the models for faster inference
29
- model = torch.jit.script(model)
30
- vocoder = torch.jit.script(vocoder)
 
 
31
 
32
  # Use inference mode for faster computation
33
  @torch.inference_mode()
34
  def text_to_speech(text):
35
- inputs = processor(text=text, return_tensors="pt")
36
  speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
 
37
  output_path = "output.wav"
38
  sf.write(output_path, speech.numpy(), samplerate=16000)
39
  return output_path
 
22
  )
23
  return quantized_model
24
 
25
+ # Only quantize the vocoder, as the main model might not be compatible
26
  vocoder = quantize_model(vocoder)
27
 
28
+ # Move models to GPU if available
29
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
30
+ model = model.to(device)
31
+ vocoder = vocoder.to(device)
32
+ speaker_embeddings = speaker_embeddings.to(device)
33
 
34
  # Use inference mode for faster computation
35
  @torch.inference_mode()
36
  def text_to_speech(text):
37
+ inputs = processor(text=text, return_tensors="pt").to(device)
38
  speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
39
+ speech = speech.cpu() # Move back to CPU for saving
40
  output_path = "output.wav"
41
  sf.write(output_path, speech.numpy(), samplerate=16000)
42
  return output_path