owiedotch commited on
Commit
5956a6f
1 Parent(s): 0586f5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -13
app.py CHANGED
@@ -7,8 +7,6 @@ from dac_jax.audio_utils import volume_norm, db2linear
7
  import io
8
  import soundfile as sf
9
  import spaces
10
- import tempfile
11
- import os
12
 
13
  # Check for CUDA availability and set device
14
  try:
@@ -31,15 +29,10 @@ def decompress_chunk(c):
31
  return model.apply(variables, c, method='decompress_chunk')
32
 
33
  @spaces.GPU
34
- def encode(audio_file):
35
  try:
36
- # Save the uploaded audio to a temporary file
37
- with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
38
- temp_audio_file.write(audio_file.read())
39
- temp_audio_file_path = temp_audio_file.name
40
-
41
- # Load a mono audio file from the temporary file path
42
- signal, sample_rate = librosa.load(temp_audio_file_path, sr=44100, mono=True)
43
 
44
  signal = jnp.array(signal, dtype=jnp.float32)
45
  while signal.ndim < 3:
@@ -61,9 +54,6 @@ def encode(audio_file):
61
  except Exception as e:
62
  gr.Warning(f"An error occurred during encoding: {e}")
63
  return None
64
- finally:
65
- # Clean up the temporary file
66
- os.remove(temp_audio_file_path)
67
 
68
  @spaces.GPU
69
  def decode(compressed_dac_file):
 
7
  import io
8
  import soundfile as sf
9
  import spaces
 
 
10
 
11
  # Check for CUDA availability and set device
12
  try:
 
29
  return model.apply(variables, c, method='decompress_chunk')
30
 
31
  @spaces.GPU
32
+ def encode(audio_file_path):
33
  try:
34
+ # Load a mono audio file directly from the file path
35
+ signal, sample_rate = librosa.load(audio_file_path, sr=44100, mono=True)
 
 
 
 
 
36
 
37
  signal = jnp.array(signal, dtype=jnp.float32)
38
  while signal.ndim < 3:
 
54
  except Exception as e:
55
  gr.Warning(f"An error occurred during encoding: {e}")
56
  return None
 
 
 
57
 
58
  @spaces.GPU
59
  def decode(compressed_dac_file):