fantos commited on
Commit
20fef4b
·
verified ·
1 Parent(s): a638b1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -9,17 +9,25 @@ def get_available_speakers():
9
  speakers = list(_DEFAULT_SPEAKERS.keys())
10
  return speakers
11
 
 
 
 
 
 
12
  @spaces.GPU
13
  def generate_tts(text, temperature, repetition_penalty, speaker_selection, reference_audio):
14
- model_config = outetts.HFModelConfig_v2(
15
- model_path="OuteAI/OuteTTS-0.3-1B",
16
- tokenizer_path="OuteAI/OuteTTS-0.3-1B",
17
- dtype=torch.bfloat16,
18
- device="cuda"
19
- )
20
- interface = outetts.InterfaceHF(model_version="0.3", cfg=model_config)
21
-
22
  try:
 
 
 
 
 
 
 
 
23
  if reference_audio:
24
  speaker = interface.create_speaker(reference_audio)
25
  elif speaker_selection and speaker_selection != "None":
@@ -41,8 +49,16 @@ def generate_tts(text, temperature, repetition_penalty, speaker_selection, refer
41
 
42
  output_path = "output.wav"
43
  output.save(output_path)
 
 
 
 
 
 
 
44
  return output_path, None
45
  except Exception as e:
 
46
  return None, str(e)
47
 
48
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as demo:
@@ -114,4 +130,5 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as demo:
114
  outputs=[error_box]
115
  )
116
 
117
- demo.launch()
 
 
9
  speakers = list(_DEFAULT_SPEAKERS.keys())
10
  return speakers
11
 
12
+ def cleanup_cuda():
13
+ torch.cuda.empty_cache()
14
+ if torch.cuda.is_available():
15
+ torch.cuda.synchronize()
16
+
17
  @spaces.GPU
18
  def generate_tts(text, temperature, repetition_penalty, speaker_selection, reference_audio):
19
+ # Clear CUDA cache before starting
20
+ cleanup_cuda()
21
+
 
 
 
 
 
22
  try:
23
+ model_config = outetts.HFModelConfig_v2(
24
+ model_path="OuteAI/OuteTTS-0.3-1B",
25
+ tokenizer_path="OuteAI/OuteTTS-0.3-1B",
26
+ dtype=torch.bfloat16,
27
+ device="cuda"
28
+ )
29
+ interface = outetts.InterfaceHF(model_version="0.3", cfg=model_config)
30
+
31
  if reference_audio:
32
  speaker = interface.create_speaker(reference_audio)
33
  elif speaker_selection and speaker_selection != "None":
 
49
 
50
  output_path = "output.wav"
51
  output.save(output_path)
52
+
53
+ # Cleanup after generation
54
+ cleanup_cuda()
55
+ del interface
56
+ del model_config
57
+ del output
58
+
59
  return output_path, None
60
  except Exception as e:
61
+ cleanup_cuda()
62
  return None, str(e)
63
 
64
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as demo:
 
130
  outputs=[error_box]
131
  )
132
 
133
+ if __name__ == "__main__":
134
+ demo.launch()