diff --git a/setup.py b/setup.py index 46997e7..bca94e3 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,27 @@ from distutils.core import setup +from distutils.extension import Extension from Cython.Build import cythonize import numpy, os, sys if sys.platform == 'darwin': - os.environ['CFLAGS'] = '-DGGML_USE_ACCELERATE -O3 -std=c11' + os.environ['CFLAGS'] = '-DGGML_USE_ACCELERATE -O3 -std=gnu11' os.environ['CXXFLAGS'] = '-DGGML_USE_ACCELERATE -O3 -std=c++11' os.environ['LDFLAGS'] = '-framework Accelerate' else: - os.environ['CFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 -std=c11' + os.environ['CFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 -std=gnu11' os.environ['CXXFLAGS'] = '-mavx -mavx2 -mfma -mf16c -O3 -std=c++11' +ext_modules = [ + Extension( + name="whispercpp", + sources=["whispercpp.pyx", "whisper.cpp/whisper.cpp"], + language="c++", + extra_compile_args=["-std=c++11"], + ) +] +ext_modules = cythonize(ext_modules) + +whisper_clib = ('whisper_clib', {'sources': ['whisper.cpp/ggml.c']}) setup( name='whispercpp', @@ -17,6 +29,7 @@ setup( description='Python bindings for whisper.cpp', author='Luke Southam', author_email='luke@devthe.com', + libraries=[whisper_clib], ext_modules = cythonize("whispercpp.pyx"), include_dirs = ['./whisper.cpp/', numpy.get_include()], install_requires=[ diff --git a/whispercpp.pyx b/whispercpp.pyx index 2f853bc..fba2eff 100644 --- a/whispercpp.pyx +++ b/whispercpp.pyx @@ -1,7 +1,5 @@ #!python # cython: language_level=3 -# distutils: language = c++ -# distutils: sources= ./whisper.cpp/whisper.cpp ./whisper.cpp/ggml.c import ffmpeg import numpy as np @@ -9,7 +7,7 @@ import requests import os from pathlib import Path -MODELS_DIR = str(Path('~/ggml-models').expanduser()) +MODELS_DIR = str(Path('~/.ggml-models').expanduser()) print("Saving models to:", MODELS_DIR) @@ -39,6 +37,7 @@ def download_model(model): print(f'Downloading {model}...') url = MODELS[model] r = requests.get(url, allow_redirects=True) + os.makedirs(MODELS_DIR, exist_ok=True) with open(Path(MODELS_DIR).joinpath(model), 'wb') as f: f.write(r.content)