badayvedat commited on
Commit
38cb277
1 Parent(s): 5638854

Load local model

Browse files
Files changed (1) hide show
  1. app.py +7 -44
app.py CHANGED
@@ -15,7 +15,11 @@ DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
 
16
  # The model will be loaded in the future
17
  MODEL_NAME = CHECKPOINTS_DIR / "audiosep_base_4M_steps.ckpt"
18
- MODEL = None
 
 
 
 
19
 
20
 
21
  description = """
@@ -28,15 +32,6 @@ numerous tasks such as audio event separation, musical instrument separation, an
28
  """
29
 
30
 
31
- def get_model():
32
- model = build_audiosep(
33
- config_yaml="config/audiosep_base.yaml",
34
- checkpoint_path=MODEL_NAME,
35
- device=DEVICE,
36
- )
37
- return model
38
-
39
-
40
  def inference(audio_file_path: str, text: str):
41
  print(f"Separate audio from [{audio_file_path}] with textual query [{text}]")
42
  mixture, _ = librosa.load(audio_file_path, sr=32000, mono=True)
@@ -60,36 +55,6 @@ def inference(audio_file_path: str, text: str):
60
  return 32000, np.round(sep_segment * 32767).astype(np.int16)
61
 
62
 
63
- def download_models():
64
- CHECKPOINTS_DIR.mkdir(exist_ok=True)
65
- success_file = CHECKPOINTS_DIR / "_SUCCESS"
66
-
67
- models = (
68
- (
69
- "https://drive.google.com/file/d/1wQuXThdATXrkmkPM2sRGaNapJ4mTqmlY/view?usp=sharing",
70
- MODEL_NAME,
71
- ),
72
- (
73
- "https://drive.google.com/file/d/11oj8_tPG6SXgw5fIEsZ5HiWZnJOrvdhw/view?usp=sharing",
74
- CHECKPOINTS_DIR / "music_speech_audioset_epoch_15_esc_89.98.pt",
75
- ),
76
- )
77
-
78
- def download(models):
79
- for model_url, model_path in models:
80
- gdown.download(model_url, str(model_path), quiet=False, fuzzy=True)
81
-
82
- success_file.touch()
83
-
84
- global MODEL
85
- MODEL = get_model()
86
- button.update(value="Separate", interactive=True)
87
-
88
- if not success_file.exists():
89
- thread = Thread(target=download, args=[models])
90
- thread.start()
91
-
92
-
93
  with gr.Blocks(title="AudioSep") as demo:
94
  gr.Markdown(description)
95
  with gr.Row():
@@ -100,16 +65,14 @@ with gr.Blocks(title="AudioSep") as demo:
100
  with gr.Column():
101
  output_audio = gr.Audio(scale=10)
102
  button = gr.Button(
103
- "Downloading the models...",
104
  variant="primary",
105
  scale=2,
106
  size="lg",
107
- interactive=False,
108
  )
109
  button.click(
110
  fn=inference, inputs=[input_audio, text], outputs=[output_audio]
111
  )
112
 
113
- download_models()
114
-
115
  demo.queue().launch(share=True)
 
15
 
16
  # The model will be loaded in the future
17
  MODEL_NAME = CHECKPOINTS_DIR / "audiosep_base_4M_steps.ckpt"
18
+ MODEL = build_audiosep(
19
+ config_yaml="config/audiosep_base.yaml",
20
+ checkpoint_path=MODEL_NAME,
21
+ device=DEVICE,
22
+ )
23
 
24
 
25
  description = """
 
32
  """
33
 
34
 
 
 
 
 
 
 
 
 
 
35
  def inference(audio_file_path: str, text: str):
36
  print(f"Separate audio from [{audio_file_path}] with textual query [{text}]")
37
  mixture, _ = librosa.load(audio_file_path, sr=32000, mono=True)
 
55
  return 32000, np.round(sep_segment * 32767).astype(np.int16)
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  with gr.Blocks(title="AudioSep") as demo:
59
  gr.Markdown(description)
60
  with gr.Row():
 
65
  with gr.Column():
66
  output_audio = gr.Audio(scale=10)
67
  button = gr.Button(
68
+ "Separate",
69
  variant="primary",
70
  scale=2,
71
  size="lg",
72
+ interactive=True,
73
  )
74
  button.click(
75
  fn=inference, inputs=[input_audio, text], outputs=[output_audio]
76
  )
77
 
 
 
78
  demo.queue().launch(share=True)