Sentimon commited on
Commit
5d3bb47
·
verified ·
1 Parent(s): 939b867

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
  import os
 
3
  from huggingface_hub import hf_hub_download
4
  from audio_separator.separator import Separator
5
 
6
  # --- Configuration ---
7
  REPO_ID = "anvuew/dereverb_room"
8
- # Filenames taken from your logs
9
  MODEL_FILENAME = "dereverb_room_anvuew_sdr_13.7432.ckpt"
10
  CONFIG_FILENAME = "dereverb_room_anvuew.yaml"
11
  # ---------------------
@@ -14,26 +14,43 @@ def inference(audio_path):
14
  if not audio_path:
15
  return None
16
 
17
- print("Downloading model files if missing...")
18
- model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
19
- config_path = hf_hub_download(repo_id=REPO_ID, filename=CONFIG_FILENAME)
 
 
 
 
 
 
20
 
21
  print("Initializing separator...")
22
- # Initialize WITHOUT model paths first
23
  separator = Separator(
24
  output_dir=".",
25
  output_format="FLAC"
26
  )
27
 
28
- print(f"Loading model: {MODEL_FILENAME}...")
29
- # Load the specific model and config using their absolute downloaded paths
30
- separator.load_model(model_filename=model_path, config_filename=config_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  print("Starting inference...")
33
  output_files = separator.separate(audio_path)
34
 
35
  print(f"Separation complete. Outputs: {output_files}")
36
- # Return the first output file
37
  return output_files[0]
38
 
39
  with gr.Blocks(title="Dereverb Room Web UI") as demo:
 
1
  import gradio as gr
2
  import os
3
+ import shutil
4
  from huggingface_hub import hf_hub_download
5
  from audio_separator.separator import Separator
6
 
7
  # --- Configuration ---
8
  REPO_ID = "anvuew/dereverb_room"
 
9
  MODEL_FILENAME = "dereverb_room_anvuew_sdr_13.7432.ckpt"
10
  CONFIG_FILENAME = "dereverb_room_anvuew.yaml"
11
  # ---------------------
 
14
  if not audio_path:
15
  return None
16
 
17
+ print("Downloading model files...")
18
+ # Download to a specific local directory to ensure they are together
19
+ os.makedirs("models", exist_ok=True)
20
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME, local_dir="models")
21
+ config_path = hf_hub_download(repo_id=REPO_ID, filename=CONFIG_FILENAME, local_dir="models")
22
+
23
+ # Rename config to match model filename if they differ significantly,
24
+ # though standard loading might just work if they are in the same dir.
25
+ # Let's try standard loading first by just pointing to the checkpoint.
26
 
27
  print("Initializing separator...")
 
28
  separator = Separator(
29
  output_dir=".",
30
  output_format="FLAC"
31
  )
32
 
33
+ print(f"Loading model from {model_path}...")
34
+ # Simply pass the model path. The library usually looks for a .yaml
35
+ # with a matching name or the specific config it needs in the same dir.
36
+ # If it strictly needs the config passed, we might need to use a different method
37
+ # but standard usage often just takes the model file if packaged correctly.
38
+ # Let's try to pass JUST the model path first as per common usage.
39
+ #
40
+ # NOTE: If this still fails because it can't find the config, we will need
41
+ # to rename 'dereverb_room_anvuew.yaml' to 'dereverb_room_anvuew_sdr_13.7432.yaml'
42
+
43
+ expected_config_path = os.path.splitext(model_path)[0] + ".yaml"
44
+ if not os.path.exists(expected_config_path):
45
+ print(f"Renaming config to {expected_config_path} for auto-discovery...")
46
+ shutil.copy(config_path, expected_config_path)
47
+
48
+ separator.load_model(model_filename=model_path)
49
 
50
  print("Starting inference...")
51
  output_files = separator.separate(audio_path)
52
 
53
  print(f"Separation complete. Outputs: {output_files}")
 
54
  return output_files[0]
55
 
56
  with gr.Blocks(title="Dereverb Room Web UI") as demo: