mason369 commited on
Commit
9718307
·
verified ·
1 Parent(s): 8fe1fb3

Install audio-separator CPU extra on HF

Browse files
infer/cover_pipeline.py CHANGED
@@ -23,6 +23,7 @@ from infer.separator import (
23
  KARAOKE_DEFAULT_MODEL,
24
  check_demucs_available,
25
  check_roformer_available,
 
26
  get_available_models,
27
  )
28
  from infer.official_adapter import (
@@ -591,8 +592,11 @@ class CoverPipeline:
591
  # Roformer 模式
592
  if model_name == "roformer":
593
  if not check_roformer_available():
 
 
594
  raise ImportError(
595
- "请安装 audio-separator: pip install audio-separator[gpu]"
 
596
  )
597
  if (
598
  self.separator is not None
 
23
  KARAOKE_DEFAULT_MODEL,
24
  check_demucs_available,
25
  check_roformer_available,
26
+ get_audio_separator_unavailable_reason,
27
  get_available_models,
28
  )
29
  from infer.official_adapter import (
 
592
  # Roformer 模式
593
  if model_name == "roformer":
594
  if not check_roformer_available():
595
+ reason = get_audio_separator_unavailable_reason()
596
+ suffix = f";原始错误: {reason}" if reason else ""
597
  raise ImportError(
598
+ "请安装 audio-separator[cpu] audio-separator[gpu]"
599
+ f"{suffix}"
600
  )
601
  if (
602
  self.separator is not None
infer/separator.py CHANGED
@@ -10,6 +10,7 @@ import shutil
10
  import torch
11
  import numpy as np
12
  import soundfile as sf
 
13
  from pathlib import Path
14
  from typing import Tuple, Optional, Callable, Union
15
 
@@ -29,16 +30,35 @@ except ImportError:
29
  try:
30
  from audio_separator.separator import Separator
31
  AUDIO_SEPARATOR_AVAILABLE = True
 
32
  # 抑制 audio-separator 的英文日志,我们有自己的中文日志
33
- import logging as _logging
34
  _logging.getLogger("audio_separator").setLevel(_logging.WARNING)
35
- except ImportError:
 
36
  AUDIO_SEPARATOR_AVAILABLE = False
 
37
 
38
 
39
  ModelSpec = Union[str, list[str], tuple[str, ...]]
40
 
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  # Public scored SOTA defaults from audio-separator 0.44.1's model table.
43
  # Keep the cover pipeline unchanged; only the separator model choices change.
44
  ENSEMBLE_PRESET_PREFIX = "ensemble:"
@@ -185,9 +205,7 @@ class RoformerSeparator:
185
  device: str = "cuda",
186
  ):
187
  if not AUDIO_SEPARATOR_AVAILABLE:
188
- raise ImportError(
189
- "请安装 audio-separator: pip install audio-separator[gpu]"
190
- )
191
  self.model_filename = model_filename
192
  self.model_candidates = [model_filename]
193
  self.device = str(get_device(device))
@@ -354,9 +372,7 @@ class KaraokeSeparator:
354
  device: str = "cuda",
355
  ):
356
  if not AUDIO_SEPARATOR_AVAILABLE:
357
- raise ImportError(
358
- "请安装 audio-separator: pip install audio-separator[gpu]"
359
- )
360
  self.device = str(get_device(device))
361
  self.separator = None
362
  self.active_model = None
@@ -521,9 +537,7 @@ class RoformerDereverbSeparator:
521
  device: str = "cuda",
522
  ):
523
  if not AUDIO_SEPARATOR_AVAILABLE:
524
- raise ImportError(
525
- "请安装 audio-separator: pip install audio-separator[gpu]"
526
- )
527
  self.device = str(get_device(device))
528
  self.separator = None
529
  self.active_model = None
 
10
  import torch
11
  import numpy as np
12
  import soundfile as sf
13
+ import logging as _logging
14
  from pathlib import Path
15
  from typing import Tuple, Optional, Callable, Union
16
 
 
30
  try:
31
  from audio_separator.separator import Separator
32
  AUDIO_SEPARATOR_AVAILABLE = True
33
+ AUDIO_SEPARATOR_IMPORT_ERROR = None
34
  # 抑制 audio-separator 的英文日志,我们有自己的中文日志
 
35
  _logging.getLogger("audio_separator").setLevel(_logging.WARNING)
36
+ except ImportError as exc:
37
+ Separator = None
38
  AUDIO_SEPARATOR_AVAILABLE = False
39
+ AUDIO_SEPARATOR_IMPORT_ERROR = exc
40
 
41
 
42
  ModelSpec = Union[str, list[str], tuple[str, ...]]
43
 
44
 
45
+ def get_audio_separator_unavailable_reason() -> str:
46
+ """Return the original audio-separator import failure, if any."""
47
+ if AUDIO_SEPARATOR_AVAILABLE:
48
+ return ""
49
+ if AUDIO_SEPARATOR_IMPORT_ERROR is None:
50
+ return "audio-separator 未安装或不可导入"
51
+ return str(AUDIO_SEPARATOR_IMPORT_ERROR)
52
+
53
+
54
+ def _audio_separator_install_message() -> str:
55
+ message = "请安装 audio-separator[cpu] 或 audio-separator[gpu]"
56
+ reason = get_audio_separator_unavailable_reason()
57
+ if reason:
58
+ message += f";原始错误: {reason}"
59
+ return message
60
+
61
+
62
  # Public scored SOTA defaults from audio-separator 0.44.1's model table.
63
  # Keep the cover pipeline unchanged; only the separator model choices change.
64
  ENSEMBLE_PRESET_PREFIX = "ensemble:"
 
205
  device: str = "cuda",
206
  ):
207
  if not AUDIO_SEPARATOR_AVAILABLE:
208
+ raise ImportError(_audio_separator_install_message())
 
 
209
  self.model_filename = model_filename
210
  self.model_candidates = [model_filename]
211
  self.device = str(get_device(device))
 
372
  device: str = "cuda",
373
  ):
374
  if not AUDIO_SEPARATOR_AVAILABLE:
375
+ raise ImportError(_audio_separator_install_message())
 
 
376
  self.device = str(get_device(device))
377
  self.separator = None
378
  self.active_model = None
 
537
  device: str = "cuda",
538
  ):
539
  if not AUDIO_SEPARATOR_AVAILABLE:
540
+ raise ImportError(_audio_separator_install_message())
 
 
541
  self.device = str(get_device(device))
542
  self.separator = None
543
  self.active_model = None
requirements.txt CHANGED
@@ -32,7 +32,7 @@ python-dotenv>=1.0.0
32
  colorama>=0.4.6
33
 
34
  # AI 翻唱功能(核心)
35
- audio-separator==0.44.1
36
  huggingface_hub>=0.19.0,<1.0
37
  pedalboard>=0.7.0
38
  ffmpeg-python>=0.2.0
 
32
  colorama>=0.4.6
33
 
34
  # AI 翻唱功能(核心)
35
+ audio-separator[cpu]==0.44.1
36
  huggingface_hub>=0.19.0,<1.0
37
  pedalboard>=0.7.0
38
  ffmpeg-python>=0.2.0
requirements_hf.txt CHANGED
@@ -32,7 +32,7 @@ python-dotenv>=1.0.0
32
  colorama>=0.4.6
33
 
34
  # AI 翻唱功能(核心)
35
- audio-separator==0.44.1
36
  huggingface_hub>=0.19.0,<1.0
37
  pedalboard>=0.7.0
38
  ffmpeg-python>=0.2.0
 
32
  colorama>=0.4.6
33
 
34
  # AI 翻唱功能(核心)
35
+ audio-separator[cpu]==0.44.1
36
  huggingface_hub>=0.19.0,<1.0
37
  pedalboard>=0.7.0
38
  ffmpeg-python>=0.2.0
tests/test_hf_entrypoint.py CHANGED
@@ -39,7 +39,7 @@ class HuggingFaceEntrypointTests(unittest.TestCase):
39
  self.assertIn("jinja2>=3.1,<4", requirements)
40
  self.assertIn("pandas>=2,<3", requirements)
41
  self.assertIn("numpy>=2,<3", requirements)
42
- self.assertIn("audio-separator==0.44.1", requirements)
43
  self.assertIn("huggingface_hub>=0.19.0,<1.0", requirements)
44
 
45
 
 
39
  self.assertIn("jinja2>=3.1,<4", requirements)
40
  self.assertIn("pandas>=2,<3", requirements)
41
  self.assertIn("numpy>=2,<3", requirements)
42
+ self.assertIn("audio-separator[cpu]==0.44.1", requirements)
43
  self.assertIn("huggingface_hub>=0.19.0,<1.0", requirements)
44
 
45