Merge pull request #9 from rlrs/main

Fixed wheel builds and model downloads
This commit is contained in:
Luke Southam 2023-02-13 09:00:58 +00:00 committed by GitHub
commit e2581c8aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -1,15 +1,27 @@
from distutils.core import setup from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize from Cython.Build import cythonize
import numpy, os, sys import numpy, os, sys
if sys.platform == 'darwin': 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['CXXFLAGS'] = '-DGGML_USE_ACCELERATE -O3 -std=c++11'
os.environ['LDFLAGS'] = '-framework Accelerate' os.environ['LDFLAGS'] = '-framework Accelerate'
else: 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' 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( setup(
name='whispercpp', name='whispercpp',
@ -17,6 +29,7 @@ setup(
description='Python bindings for whisper.cpp', description='Python bindings for whisper.cpp',
author='Luke Southam', author='Luke Southam',
author_email='luke@devthe.com', author_email='luke@devthe.com',
libraries=[whisper_clib],
ext_modules = cythonize("whispercpp.pyx"), ext_modules = cythonize("whispercpp.pyx"),
include_dirs = ['./whisper.cpp/', numpy.get_include()], include_dirs = ['./whisper.cpp/', numpy.get_include()],
install_requires=[ install_requires=[

View File

@ -1,7 +1,5 @@
#!python #!python
# cython: language_level=3 # cython: language_level=3
# distutils: language = c++
# distutils: sources= ./whisper.cpp/whisper.cpp ./whisper.cpp/ggml.c
import ffmpeg import ffmpeg
import numpy as np import numpy as np
@ -9,7 +7,7 @@ import requests
import os import os
from pathlib import Path from pathlib import Path
MODELS_DIR = str(Path('~/ggml-models').expanduser()) MODELS_DIR = str(Path('~/.ggml-models').expanduser())
print("Saving models to:", MODELS_DIR) print("Saving models to:", MODELS_DIR)
@ -39,6 +37,7 @@ def download_model(model):
print(f'Downloading {model}...') print(f'Downloading {model}...')
url = MODELS[model] url = MODELS[model]
r = requests.get(url, allow_redirects=True) r = requests.get(url, allow_redirects=True)
os.makedirs(MODELS_DIR, exist_ok=True)
with open(Path(MODELS_DIR).joinpath(model), 'wb') as f: with open(Path(MODELS_DIR).joinpath(model), 'wb') as f:
f.write(r.content) f.write(r.content)