Katsuya Oda commited on
Commit
81bcdf3
1 Parent(s): 2c6a571

fix: impl handler

Browse files
.gitattributes CHANGED
@@ -24,4 +24,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
  *.xz filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
 
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
24
  *.xz filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *.wav filter=lfs diff=lfs merge=lfs -text
28
  *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.9.13
config.yaml CHANGED
@@ -5,7 +5,7 @@ pipeline:
5
  embedding: speechbrain/spkrec-ecapa-voxceleb
6
  embedding_batch_size: 32
7
  embedding_exclude_overlap: true
8
- segmentation: pyannote/segmentation@2022.07
9
  segmentation_batch_size: 32
10
 
11
  params:
 
5
  embedding: speechbrain/spkrec-ecapa-voxceleb
6
  embedding_batch_size: 32
7
  embedding_exclude_overlap: true
8
+ segmentation: pyannote_segmentation_2022_07_pythorch_model.bin
9
  segmentation_batch_size: 32
10
 
11
  params:
handler.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+ from pyannote.audio import Pipeline
3
+ from io import BytesIO
4
+ import torch
5
+ import torchaudio
6
+
7
+
8
+ class EndpointHandler:
9
+ def __init__(self, path=""):
10
+ # load the model
11
+ self.pipeline = Pipeline.from_pretrained("config.yaml")
12
+
13
+ def __call__(self, data: Dict[str, bytes]) -> Dict[str, str]:
14
+ """
15
+ Args:
16
+ data (:obj:):
17
+ includes the deserialized audio file as bytes
18
+ Return:
19
+ A :obj:`dict`:. base64 encoded image
20
+ """
21
+ # process input
22
+ inputs = data.pop("inputs", data)
23
+ parameters = data.pop("parameters", None) # min_speakers=2, max_speakers=5
24
+
25
+ waveform, sample_rate = torchaudio.load(BytesIO(inputs))
26
+ pyannote_input = {"waveform": waveform, "sample_rate": sample_rate}
27
+
28
+ # apply pretrained pipeline
29
+ # pass inputs with all kwargs in data
30
+ if parameters is not None:
31
+ diarization = self.pipeline(pyannote_input, **parameters)
32
+ else:
33
+ diarization = self.pipeline(pyannote_input)
34
+
35
+ # postprocess the prediction
36
+ processed_diarization = [
37
+ {"label": str(label), "start": str(segment.start), "stop": str(segment.end)}
38
+ for segment, _, label in diarization.itertracks(yield_label=True)
39
+ ]
40
+
41
+ return {"diarization": processed_diarization}
handler_test.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from handler import EndpointHandler
2
+ from pathlib import Path
3
+
4
+ my_handler = EndpointHandler()
5
+
6
+ with open("./handler_test.wav", "rb") as file:
7
+ bytes_data = file.read()
8
+ res = my_handler({"inputs": bytes_data})
9
+ print(res)
handler_test.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:187386cda67317574da5b30068a8b853e52cc6df0d13abfec381912dfa9e7461
3
+ size 1920062
pyannote_segmentation_2022_07_pythorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b5b3216d60a2d32fc086b47ea8c67589aaeb26b7e07fcbe620d6d0b83e209ea
3
+ size 17719103
pyproject.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "pyannote-speaker-diarization"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ authors = [
6
+ { name = "Katsuya Oda", email = "[email protected]" }
7
+ ]
8
+ dependencies = [
9
+ "pyannote.audio @ git+https://github.com/pyannote/[email protected]",
10
+ "torch==1.13.1",
11
+ "black>=23.7.0",
12
+ ]
13
+ readme = "README.md"
14
+ requires-python = ">= 3.8"
15
+
16
+ [build-system]
17
+ requires = ["hatchling"]
18
+ build-backend = "hatchling.build"
19
+
20
+ [tool.rye]
21
+ managed = true
22
+ dev-dependencies = []
23
+
24
+ [tool.hatch.metadata]
25
+ allow-direct-references = true
requirements-dev.lock ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # generated by rye
2
+ # use `rye lock` or `rye sync` to update this lockfile
3
+ #
4
+ # last locked with the following flags:
5
+ # pre: false
6
+ # features: []
7
+ # all-features: false
8
+
9
+ -e file:.
10
+ absl-py==1.4.0
11
+ aiohttp==3.8.5
12
+ aiosignal==1.3.1
13
+ alembic==1.11.2
14
+ antlr4-python3-runtime==4.9.3
15
+ asteroid-filterbanks==0.4.0
16
+ async-timeout==4.0.2
17
+ attrs==23.1.0
18
+ audioread==3.0.0
19
+ backports-cached-property==1.0.2
20
+ black==23.7.0
21
+ cachetools==5.3.1
22
+ certifi==2023.7.22
23
+ cffi==1.15.1
24
+ charset-normalizer==3.2.0
25
+ click==8.1.6
26
+ cmaes==0.10.0
27
+ colorama==0.4.6
28
+ colorlog==6.7.0
29
+ contourpy==1.1.0
30
+ cycler==0.11.0
31
+ decorator==5.1.1
32
+ docopt==0.6.2
33
+ einops==0.3.2
34
+ filelock==3.12.2
35
+ fonttools==4.42.0
36
+ frozenlist==1.4.0
37
+ fsspec==2023.6.0
38
+ google-auth==2.22.0
39
+ google-auth-oauthlib==1.0.0
40
+ greenlet==2.0.2
41
+ grpcio==1.56.2
42
+ hmmlearn==0.2.8
43
+ huggingface-hub==0.16.4
44
+ hyperpyyaml==1.2.1
45
+ idna==3.4
46
+ importlib-metadata==6.8.0
47
+ importlib-resources==6.0.1
48
+ joblib==1.3.1
49
+ julius==0.2.7
50
+ kiwisolver==1.4.4
51
+ librosa==0.9.2
52
+ llvmlite==0.40.1
53
+ mako==1.2.4
54
+ markdown==3.4.4
55
+ markdown-it-py==3.0.0
56
+ markupsafe==2.1.3
57
+ matplotlib==3.7.2
58
+ mdurl==0.1.2
59
+ mpmath==1.3.0
60
+ multidict==6.0.4
61
+ mypy-extensions==1.0.0
62
+ networkx==2.8.8
63
+ numba==0.57.1
64
+ numpy==1.24.4
65
+ nvidia-cublas-cu11==11.10.3.66
66
+ nvidia-cuda-nvrtc-cu11==11.7.99
67
+ nvidia-cuda-runtime-cu11==11.7.99
68
+ nvidia-cudnn-cu11==8.5.0.96
69
+ oauthlib==3.2.2
70
+ omegaconf==2.3.0
71
+ optuna==3.3.0
72
+ packaging==23.1
73
+ pandas==2.0.3
74
+ pathspec==0.11.2
75
+ pillow==10.0.0
76
+ platformdirs==3.10.0
77
+ pooch==1.7.0
78
+ primepy==1.3
79
+ protobuf==3.20.1
80
+ pyannote-audio @ git+https://github.com/pyannote/[email protected]
81
+ pyannote-core==4.5
82
+ pyannote-database==4.1.3
83
+ pyannote-metrics==3.2.1
84
+ pyannote-pipeline==2.3
85
+ pyasn1==0.5.0
86
+ pyasn1-modules==0.3.0
87
+ pycparser==2.21
88
+ pydeprecate==0.3.2
89
+ pygments==2.16.1
90
+ pyparsing==3.0.9
91
+ python-dateutil==2.8.2
92
+ pytorch-lightning==1.6.5
93
+ pytorch-metric-learning==1.7.3
94
+ pytz==2023.3
95
+ pyyaml==6.0.1
96
+ requests==2.31.0
97
+ requests-oauthlib==1.3.1
98
+ resampy==0.4.2
99
+ rich==13.5.2
100
+ rsa==4.9
101
+ ruamel-yaml==0.17.28
102
+ ruamel-yaml-clib==0.2.7
103
+ scikit-learn==1.3.0
104
+ scipy==1.11.1
105
+ semver==2.13.0
106
+ sentencepiece==0.1.99
107
+ shellingham==1.5.0.post1
108
+ simplejson==3.19.1
109
+ singledispatchmethod==1.0
110
+ six==1.16.0
111
+ sortedcontainers==2.4.0
112
+ soundfile==0.10.3.post1
113
+ speechbrain==0.5.15
114
+ sqlalchemy==2.0.19
115
+ sympy==1.12
116
+ tabulate==0.9.0
117
+ tensorboard==2.13.0
118
+ tensorboard-data-server==0.7.1
119
+ threadpoolctl==3.2.0
120
+ tomli==2.0.1
121
+ torch==1.13.1
122
+ torch-audiomentations==0.11.0
123
+ torch-pitch-shift==1.2.4
124
+ torchaudio==0.13.1
125
+ torchmetrics==0.11.4
126
+ tqdm==4.65.0
127
+ typer==0.9.0
128
+ typing-extensions==4.7.1
129
+ tzdata==2023.3
130
+ urllib3==1.26.16
131
+ werkzeug==2.3.6
132
+ wheel==0.41.1
133
+ yarl==1.9.2
134
+ zipp==3.16.2
135
+ # The following packages are considered to be unsafe in a requirements file:
136
+ setuptools==68.0.0
requirements.lock ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # generated by rye
2
+ # use `rye lock` or `rye sync` to update this lockfile
3
+ #
4
+ # last locked with the following flags:
5
+ # pre: false
6
+ # features: []
7
+ # all-features: false
8
+
9
+ -e file:.
10
+ absl-py==1.4.0
11
+ aiohttp==3.8.5
12
+ aiosignal==1.3.1
13
+ alembic==1.11.2
14
+ antlr4-python3-runtime==4.9.3
15
+ asteroid-filterbanks==0.4.0
16
+ async-timeout==4.0.2
17
+ attrs==23.1.0
18
+ audioread==3.0.0
19
+ backports-cached-property==1.0.2
20
+ black==23.7.0
21
+ cachetools==5.3.1
22
+ certifi==2023.7.22
23
+ cffi==1.15.1
24
+ charset-normalizer==3.2.0
25
+ click==8.1.6
26
+ cmaes==0.10.0
27
+ colorama==0.4.6
28
+ colorlog==6.7.0
29
+ contourpy==1.1.0
30
+ cycler==0.11.0
31
+ decorator==5.1.1
32
+ docopt==0.6.2
33
+ einops==0.3.2
34
+ filelock==3.12.2
35
+ fonttools==4.42.0
36
+ frozenlist==1.4.0
37
+ fsspec==2023.6.0
38
+ google-auth==2.22.0
39
+ google-auth-oauthlib==1.0.0
40
+ greenlet==2.0.2
41
+ grpcio==1.56.2
42
+ hmmlearn==0.2.8
43
+ huggingface-hub==0.16.4
44
+ hyperpyyaml==1.2.1
45
+ idna==3.4
46
+ importlib-metadata==6.8.0
47
+ importlib-resources==6.0.1
48
+ joblib==1.3.1
49
+ julius==0.2.7
50
+ kiwisolver==1.4.4
51
+ librosa==0.9.2
52
+ llvmlite==0.40.1
53
+ mako==1.2.4
54
+ markdown==3.4.4
55
+ markdown-it-py==3.0.0
56
+ markupsafe==2.1.3
57
+ matplotlib==3.7.2
58
+ mdurl==0.1.2
59
+ mpmath==1.3.0
60
+ multidict==6.0.4
61
+ mypy-extensions==1.0.0
62
+ networkx==2.8.8
63
+ numba==0.57.1
64
+ numpy==1.24.4
65
+ nvidia-cublas-cu11==11.10.3.66
66
+ nvidia-cuda-nvrtc-cu11==11.7.99
67
+ nvidia-cuda-runtime-cu11==11.7.99
68
+ nvidia-cudnn-cu11==8.5.0.96
69
+ oauthlib==3.2.2
70
+ omegaconf==2.3.0
71
+ optuna==3.3.0
72
+ packaging==23.1
73
+ pandas==2.0.3
74
+ pathspec==0.11.2
75
+ pillow==10.0.0
76
+ platformdirs==3.10.0
77
+ pooch==1.7.0
78
+ primepy==1.3
79
+ protobuf==3.20.1
80
+ pyannote-audio @ git+https://github.com/pyannote/[email protected]
81
+ pyannote-core==4.5
82
+ pyannote-database==4.1.3
83
+ pyannote-metrics==3.2.1
84
+ pyannote-pipeline==2.3
85
+ pyasn1==0.5.0
86
+ pyasn1-modules==0.3.0
87
+ pycparser==2.21
88
+ pydeprecate==0.3.2
89
+ pygments==2.16.1
90
+ pyparsing==3.0.9
91
+ python-dateutil==2.8.2
92
+ pytorch-lightning==1.6.5
93
+ pytorch-metric-learning==1.7.3
94
+ pytz==2023.3
95
+ pyyaml==6.0.1
96
+ requests==2.31.0
97
+ requests-oauthlib==1.3.1
98
+ resampy==0.4.2
99
+ rich==13.5.2
100
+ rsa==4.9
101
+ ruamel-yaml==0.17.28
102
+ ruamel-yaml-clib==0.2.7
103
+ scikit-learn==1.3.0
104
+ scipy==1.11.1
105
+ semver==2.13.0
106
+ sentencepiece==0.1.99
107
+ shellingham==1.5.0.post1
108
+ simplejson==3.19.1
109
+ singledispatchmethod==1.0
110
+ six==1.16.0
111
+ sortedcontainers==2.4.0
112
+ soundfile==0.10.3.post1
113
+ speechbrain==0.5.15
114
+ sqlalchemy==2.0.19
115
+ sympy==1.12
116
+ tabulate==0.9.0
117
+ tensorboard==2.13.0
118
+ tensorboard-data-server==0.7.1
119
+ threadpoolctl==3.2.0
120
+ tomli==2.0.1
121
+ torch==1.13.1
122
+ torch-audiomentations==0.11.0
123
+ torch-pitch-shift==1.2.4
124
+ torchaudio==0.13.1
125
+ torchmetrics==0.11.4
126
+ tqdm==4.65.0
127
+ typer==0.9.0
128
+ typing-extensions==4.7.1
129
+ tzdata==2023.3
130
+ urllib3==1.26.16
131
+ werkzeug==2.3.6
132
+ wheel==0.41.1
133
+ yarl==1.9.2
134
+ zipp==3.16.2
135
+ # The following packages are considered to be unsafe in a requirements file:
136
+ setuptools==68.0.0
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch==1.13.1
2
+ pyannote.audio @ git+https://github.com/pyannote/[email protected]