Skip to content

Commit

Permalink
add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhendong committed Dec 3, 2024
1 parent bcd0a7f commit fcd500e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
show-source = true
statistics = true
max-line-length = 120
ignore = E203, E266, E501, W503
19 changes: 19 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: black

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: "--line-length=120 --check --diff --color"
22 changes: 22 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: flake8

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install flake8
run: |
python -m pip install -U flake8
- name: Lint with flake8
run: |
flake8 --config=.flake8 pyannote_onnx
22 changes: 22 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: isort

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install isort
run: |
python -m pip install -U isort
- name: Check that imports are sorted
run: |
isort --check --profile=black --line-length=120 --diff pyannote_onnx
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/psf/black
rev: main
hooks:
- id: black
args: [--line-length=120]

- repo: https://github.com/PyCQA/flake8
rev: main
hooks:
- id: flake8
args: [--config=.flake8, --ignore=E203]

- repo: https://github.com/pycqa/isort
rev: main
hooks:
- id: isort
args: [--profile=black, --line-length=120]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: main
hooks:
- id: check-executables-have-shebangs
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
4 changes: 3 additions & 1 deletion pyannote_onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .pyannote_onnx import *
from .pyannote_onnx import PyannoteONNX

__all__ = ["PyannoteONNX"]
12 changes: 3 additions & 9 deletions pyannote_onnx/pyannote_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@


class PyannoteONNX:
def __init__(
self, model_name: str = "segmentation-3.0", show_progress: bool = False
):
def __init__(self, model_name: str = "segmentation-3.0", show_progress: bool = False):
configs = {
"segmentation": {
"duration": 5,
Expand Down Expand Up @@ -53,9 +51,7 @@ def __init__(
self.show_progress = show_progress
self.num_speakers = configs[model_name]["num_speakers"]
self.duration = configs[model_name]["duration"] * self.sample_rate
onnx_model = model_file_download(
"pengzhendong/pyannote-audio", f"{model_name}.onnx"
)
onnx_model = model_file_download("pengzhendong/pyannote-audio", f"{model_name}.onnx")
self.session = PickableInferenceSession(onnx_model)

@staticmethod
Expand Down Expand Up @@ -98,9 +94,7 @@ def sliding_window(waveform, window_size, step_size):
@staticmethod
def reorder(x, y):
perms = [np.array(perm).T for perm in permutations(y.T)]
diffs = np.sum(
np.abs(np.sum(np.array(perms)[:, : x.shape[0], :] - x, axis=1)), axis=1
)
diffs = np.sum(np.abs(np.sum(np.array(perms)[:, : x.shape[0], :] - x, axis=1)), axis=1)
return perms[np.argmin(diffs)]

def __call__(self, x, step=None, return_chunk=False):
Expand Down

0 comments on commit fcd500e

Please sign in to comment.