Shokoufehhh commited on
Commit
0a67d6d
1 Parent(s): 793652a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -18,8 +18,8 @@ args = {
18
  "device": "cuda" if torch.cuda.is_available() else "cpu"
19
  }
20
 
21
- # Load the pre-trained model
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
- # Save the enhanced audio to a temporary file for Gradio output
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")