Fabrice-TIERCELIN commited on
Commit
f539bd9
·
verified ·
1 Parent(s): 655cf9d

Automatic device detection

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -15,9 +15,20 @@ model_name = "tts_models/multilingual/multi-dataset/xtts_v2"
15
  #print(m)
16
  m = model_name
17
 
18
- tts = TTS(model_name, gpu=False)
19
- tts.to("cpu") # no GPU or Amd
20
- #tts.to("cuda") # cuda only
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, request: gr.Request):
@@ -73,7 +84,7 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, req
73
  )
74
  except RuntimeError as e :
75
  if "device-assert" in str(e):
76
- # cannot do anything on cuda device side error, need tor estart
77
  gr.Warning("Unhandled Exception encounter, please retry in a minute")
78
  print("Cuda device-assert Runtime encountered need restart")
79
  sys.exit("Exit due to cuda device-assert")
@@ -127,7 +138,7 @@ gr.Interface(
127
  gr.Textbox(
128
  label="Text Prompt",
129
  info="One or two sentences at a time is better",
130
- value="Hello, World !, here is an example of light voice cloning. Try to upload your best audio samples quality",
131
  ),
132
  gr.Dropdown(
133
  label="Language",
@@ -170,8 +181,8 @@ gr.Interface(
170
  ),
171
  ],
172
  outputs=[
173
- gr.Video(label="Waveform Visual"),
174
- gr.Audio(label="Synthesised Audio"),
175
  ],
176
  title=title,
177
  description=description,
 
15
  #print(m)
16
  m = model_name
17
 
18
+ # Automatic device detection
19
+ if torch.cuda.is_available():
20
+ # cuda only
21
+ device_type = "cuda"
22
+ device_selection = "cuda:0"
23
+ data_type = torch.float16
24
+ else:
25
+ # no GPU or Amd
26
+ device_type = "cpu"
27
+ device_selection = "cpu"
28
+ data_type = torch.float32
29
+
30
+ tts = TTS(model_name, gpu=torch.cuda.is_available())
31
+ tts.to(device_type)
32
 
33
 
34
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, request: gr.Request):
 
84
  )
85
  except RuntimeError as e :
86
  if "device-assert" in str(e):
87
+ # cannot do anything on cuda device side error, need to restart
88
  gr.Warning("Unhandled Exception encounter, please retry in a minute")
89
  print("Cuda device-assert Runtime encountered need restart")
90
  sys.exit("Exit due to cuda device-assert")
 
138
  gr.Textbox(
139
  label="Text Prompt",
140
  info="One or two sentences at a time is better",
141
+ value="Hello, World!, here is an example of light voice cloning. Try to upload your best audio samples quality",
142
  ),
143
  gr.Dropdown(
144
  label="Language",
 
181
  ),
182
  ],
183
  outputs=[
184
+ gr.Video(label="Waveform Visual", autoplay=True),
185
+ gr.Audio(label="Synthesised Audio", autoplay=False),
186
  ],
187
  title=title,
188
  description=description,