Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anuejn committed Apr 28, 2024
0 parents commit a33143b
Show file tree
Hide file tree
Showing 10 changed files with 2,252 additions and 0 deletions.
Empty file added .editorconfig
Empty file.
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm-project.org/#use-with-ide
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# decent-whisper

use the fastest whisper implementation on every hardware

```diff
- this package is highly work-in-progress and not ready for usage yet
```

## backends

Currently, this package can dispatch to (in order of preference):

1. [insanely-fast-whisper](https://github.com/Vaibhavs10/insanely-fast-whisper)
2. [lightning-whisper-mlx](https://github.com/mustafaaljadery/lightning-whisper-mlx)
3. [faster-whisper](https://github.com/SYSTRAN/faster-whisper)
1,993 changes: 1,993 additions & 0 deletions pdm.lock

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[project]
name = "decent-whisper"
version = "0.1.0"
description = "use the fastest whisper implementation on every hardware"
authors = [{ name = "Jaro Habiger", email = "[email protected]" }]
dependencies = ["faster-whisper>=1.0.1", "torch>=2.3.0"]
requires-python = ">= 3.10"
readme = "README.md"
license = { text = "AGPL-3.0" }

[project.optional-dependencies]
macOS = ["lightning-whisper-mlx>=0.0.10", "mlx>=0.12.0"]
cuda = [
"insanely-fast-whisper>=0.0.8",
"flash-attn>=2.5.8",
"transformers>=4.39.3",
]

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"


[tool.pdm]
distribution = true
9 changes: 9 additions & 0 deletions src/decent_whisper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .backends import insanely_fast_whisper, lightning_whisper_mlx, faster_whisper

def get_backend() -> str:
if insanely_fast_whisper.should_use():
return "insanely-fast-whisper"
elif lightning_whisper_mlx.should_use():
return "lightning-whisper-mlx"
else:
return "faster-whisper"
4 changes: 4 additions & 0 deletions src/decent_whisper/backends/faster_whisper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import faster_whisper
#import faster_whisper.transcribe
#from faster_whisper import WhisperModel

29 changes: 29 additions & 0 deletions src/decent_whisper/backends/insanely_fast_whisper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import torch
#from transformers import pipeline
#from transformers.utils import is_flash_attn_2_available

def should_use():
return torch.cuda.is_available()

def load_model():
pass

def transcribe():


pipe = pipeline(
"automatic-speech-recognition",
model="openai/whisper-large-v3", # select checkpoint from https://huggingface.co/openai/whisper-large-v3#model-details
torch_dtype=torch.float16,
device="cuda:0", # or mps for Mac devices
model_kwargs={"attn_implementation": "flash_attention_2"} if is_flash_attn_2_available() else {"attn_implementation": "sdpa"},
)

outputs = pipe(
"<FILE_NAME>",
chunk_length_s=30,
batch_size=24,
return_timestamps=True,
)

outputs
15 changes: 15 additions & 0 deletions src/decent_whisper/backends/lightning_whisper_mlx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#from lightning_whisper_mlx import LightningWhisperMLX

def should_use():
try:
import mlx
return True
except ImportError:
return False

def transcribe():
whisper = LightningWhisperMLX(model="distil-medium.en", batch_size=12, quant=None)

text = whisper.transcribe(audio_path="/audio.mp3")['text']

print(text)
Empty file added tests/__init__.py
Empty file.

0 comments on commit a33143b

Please sign in to comment.