Update app.py
Browse files
app.py
CHANGED
|
@@ -18,8 +18,8 @@ args = {
|
|
| 18 |
"device": "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
}
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
model = ScoreModel.load_from_checkpoint(args["ckpt"])
|
| 23 |
|
| 24 |
def enhance_speech(audio_file):
|
| 25 |
start_time = time.time() # Start the timer
|
|
@@ -52,8 +52,8 @@ def enhance_speech(audio_file):
|
|
| 52 |
# Renormalize
|
| 53 |
x_hat = x_hat * norm_factor
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
output_file = "enhanced_output.wav"
|
| 57 |
torchaudio.save(output_file, x_hat.cpu(), sr)
|
| 58 |
|
| 59 |
print(f"Processed audio in {time.time() - start_time:.2f}s")
|
|
|
|
| 18 |
"device": "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
}
|
| 20 |
|
| 21 |
+
# Ensure the model is loaded to the correct device
|
| 22 |
+
model = ScoreModel.load_from_checkpoint(args["ckpt"]).to(args["device"])
|
| 23 |
|
| 24 |
def enhance_speech(audio_file):
|
| 25 |
start_time = time.time() # Start the timer
|
|
|
|
| 52 |
# Renormalize
|
| 53 |
x_hat = x_hat * norm_factor
|
| 54 |
|
| 55 |
+
# Create a temporary path for saving the enhanced audio in Hugging Face Space
|
| 56 |
+
output_file = "/tmp/enhanced_output.wav" # Use a temporary directory
|
| 57 |
torchaudio.save(output_file, x_hat.cpu(), sr)
|
| 58 |
|
| 59 |
print(f"Processed audio in {time.time() - start_time:.2f}s")
|