SefyanKehail
commited on
Commit
·
1840c64
1
Parent(s):
490051a
cuda process in main thread issue
Browse files
app.py
CHANGED
|
@@ -26,9 +26,22 @@ def convert_speech(filename, progress=gr.Progress()):
|
|
| 26 |
if source.shape[0] > 1:
|
| 27 |
source = source[0, :].unsqueeze(0)
|
| 28 |
source = torchaudio.functional.resample(source, sr, 16000)
|
| 29 |
-
source = source.unsqueeze(0)
|
| 30 |
|
| 31 |
progress(0.6, desc="Converting speech")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Convert to the target speaker:
|
| 34 |
with torch.inference_mode():
|
|
|
|
| 26 |
if source.shape[0] > 1:
|
| 27 |
source = source[0, :].unsqueeze(0)
|
| 28 |
source = torchaudio.functional.resample(source, sr, 16000)
|
| 29 |
+
source = source.unsqueeze(0)
|
| 30 |
|
| 31 |
progress(0.6, desc="Converting speech")
|
| 32 |
+
|
| 33 |
+
# Move the tensor to GPU if available
|
| 34 |
+
if torch.cuda.is_available():
|
| 35 |
+
device = torch.device('cuda')
|
| 36 |
+
else:
|
| 37 |
+
device = torch.device('cpu')
|
| 38 |
+
source = source.to(device)
|
| 39 |
+
|
| 40 |
+
# Initialize models
|
| 41 |
+
hubert, acoustic, hifigan = initialize_models()
|
| 42 |
+
hubert = hubert.to(device)
|
| 43 |
+
acoustic = acoustic.to(device)
|
| 44 |
+
hifigan = hifigan.to(device)
|
| 45 |
|
| 46 |
# Convert to the target speaker:
|
| 47 |
with torch.inference_mode():
|