Fix build error
Browse files- backend/omnivoice_adapter.py +16 -0
- tests/test_zero_gpu.py +26 -0
backend/omnivoice_adapter.py
CHANGED
|
@@ -7,6 +7,21 @@ import soundfile as sf
|
|
| 7 |
|
| 8 |
from backend.types import VoiceConfig
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
NARRATOR_PRESETS = {
|
| 12 |
"brother-anselm": "male, warm baritone, measured, british accent",
|
|
@@ -48,6 +63,7 @@ class OmniVoiceAdapter:
|
|
| 48 |
self._backend = "omnivoice"
|
| 49 |
return self._model
|
| 50 |
|
|
|
|
| 51 |
def synthesize(
|
| 52 |
self,
|
| 53 |
*,
|
|
|
|
| 7 |
|
| 8 |
from backend.types import VoiceConfig
|
| 9 |
|
| 10 |
+
try:
|
| 11 |
+
import spaces
|
| 12 |
+
except ImportError:
|
| 13 |
+
class _SpacesShim:
|
| 14 |
+
@staticmethod
|
| 15 |
+
def GPU(fn=None, **_kwargs):
|
| 16 |
+
def decorate(inner):
|
| 17 |
+
return inner
|
| 18 |
+
|
| 19 |
+
if fn is not None:
|
| 20 |
+
return decorate(fn)
|
| 21 |
+
return decorate
|
| 22 |
+
|
| 23 |
+
spaces = _SpacesShim()
|
| 24 |
+
|
| 25 |
|
| 26 |
NARRATOR_PRESETS = {
|
| 27 |
"brother-anselm": "male, warm baritone, measured, british accent",
|
|
|
|
| 63 |
self._backend = "omnivoice"
|
| 64 |
return self._model
|
| 65 |
|
| 66 |
+
@spaces.GPU(duration=300)
|
| 67 |
def synthesize(
|
| 68 |
self,
|
| 69 |
*,
|
tests/test_zero_gpu.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import sys
|
| 3 |
+
from types import SimpleNamespace
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_omnivoice_adapter_registers_zero_gpu_decorator(monkeypatch) -> None:
|
| 7 |
+
decorated = {}
|
| 8 |
+
|
| 9 |
+
def fake_gpu(fn=None, **kwargs):
|
| 10 |
+
def decorate(inner):
|
| 11 |
+
decorated["name"] = inner.__name__
|
| 12 |
+
decorated["kwargs"] = kwargs
|
| 13 |
+
setattr(inner, "_zero_gpu_wrapped", True)
|
| 14 |
+
return inner
|
| 15 |
+
|
| 16 |
+
if fn is not None:
|
| 17 |
+
return decorate(fn)
|
| 18 |
+
return decorate
|
| 19 |
+
|
| 20 |
+
monkeypatch.setitem(sys.modules, "spaces", SimpleNamespace(GPU=fake_gpu))
|
| 21 |
+
sys.modules.pop("backend.omnivoice_adapter", None)
|
| 22 |
+
|
| 23 |
+
module = importlib.import_module("backend.omnivoice_adapter")
|
| 24 |
+
|
| 25 |
+
assert decorated == {"name": "synthesize", "kwargs": {"duration": 300}}
|
| 26 |
+
assert getattr(module.OmniVoiceAdapter.synthesize, "_zero_gpu_wrapped", False) is True
|