Spaces:
Running on Zero
Running on Zero
Commit ·
d4f3fbb
1
Parent(s): 928bb51
further cleanup and resetting device to cuda inside the process function
Browse files
app.py
CHANGED
|
@@ -18,11 +18,7 @@ model_card = ModelCard(
|
|
| 18 |
|
| 19 |
def load_audio(file_path):
|
| 20 |
audio, samplerate = torchaudio.load(file_path)
|
| 21 |
-
return audio.unsqueeze(0)
|
| 22 |
-
|
| 23 |
-
def save_audio(file_path, audio, samplerate=44100):
|
| 24 |
-
audio = audio.squeeze(0).cpu()
|
| 25 |
-
torchaudio.save(file_path, audio, samplerate)
|
| 26 |
|
| 27 |
# Load the model outside of the process function so that it only has to happen once
|
| 28 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
@@ -76,6 +72,7 @@ def process_fn(
|
|
| 76 |
input_audio_path: str
|
| 77 |
) -> str:
|
| 78 |
|
|
|
|
| 79 |
sig = load_audio(input_audio_path)
|
| 80 |
|
| 81 |
# Move audio data to device
|
|
@@ -85,8 +82,7 @@ def process_fn(
|
|
| 85 |
if sig.dim() == 2:
|
| 86 |
sig = sig.unsqueeze(0)
|
| 87 |
|
| 88 |
-
|
| 89 |
-
result = model(sig)
|
| 90 |
|
| 91 |
# Remove batch dimension
|
| 92 |
result = result.squeeze(0)
|
|
|
|
| 18 |
|
| 19 |
def load_audio(file_path):
|
| 20 |
audio, samplerate = torchaudio.load(file_path)
|
| 21 |
+
return audio.unsqueeze(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Load the model outside of the process function so that it only has to happen once
|
| 24 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 72 |
input_audio_path: str
|
| 73 |
) -> str:
|
| 74 |
|
| 75 |
+
device = torch.device("cuda")
|
| 76 |
sig = load_audio(input_audio_path)
|
| 77 |
|
| 78 |
# Move audio data to device
|
|
|
|
| 82 |
if sig.dim() == 2:
|
| 83 |
sig = sig.unsqueeze(0)
|
| 84 |
|
| 85 |
+
result = model(sig)
|
|
|
|
| 86 |
|
| 87 |
# Remove batch dimension
|
| 88 |
result = result.squeeze(0)
|