abdeladim-s / pywhispercpp

Python bindings for whisper.cpp
https://abdeladim-s.github.io/pywhispercpp/
MIT License
129 stars 15 forks source link

ERROR - unable to initialize from path #23

Closed to-aoki closed 10 months ago

to-aoki commented 10 months ago

Hello.

It cannot be initialized from any path as shown below.

from pywhispercpp.model import Model
model = Model(''/home/user/.local/share/pywhispercpp/models/ggml-large.bin'')

The following error will be output.

:
Invoked with: PosixPath('/home/user/.local/share/pywhispercpp/models/ggml-large.bin')
Segmentation fault (core dumped)

I think can initialize it by setting the Path object to str. https://github.com/abdeladim-s/pywhispercpp/blob/main/pywhispercpp/model.py#L83

abdeladim-s commented 10 months ago

Hello @to-aoki,

Did it work for normal str path ? Would you like me to add support for a Path object ?

to-aoki commented 10 months ago

@abdeladim-s Thank you for your reply.

It doesn't work with normal str path. I think it would be a convert the passed to cpp with a pathlib.Path object to primitive str.

self.model_path = str(Path(model).absolute())

abdeladim-s commented 10 months ago

Yes I understand, thanks @to-aoki for pointing that out. we just need to set the model attribute as is (it should already be str without the need to use the Path object). Could you please give it a try now ? change the source code and test it if it works ?

to-aoki commented 10 months ago

@abdeladim-s Thank you for fixing! I tried with the following command and source.

$ pip install git+https://github.com/abdeladim-s/pywhispercpp

$ cat sample.py
from pywhispercpp.model import Model

model = Model('/home/taoki/.local/share/pywhispercpp/models/ggml-large.bin')
segments = model.transcribe('jfk.wav', speed_up=True)
for segment in segments:
    print(segment.text)
$ python sample.py 
[2023-09-04 10:06:55,314] {model.py:221} INFO - Initializing the model ...
whisper_init_from_file_no_state: loading model from '/home/taoki/.local/share/pywhispercpp/models/ggml-large.bin'
whisper_model_load: loading model
:
[2023-09-04 10:07:52,549] {model.py:133} INFO - Inference time: 54.856 s
And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.
abdeladim-s commented 10 months ago

It looks perfect now. I have pushed a new version to PYPI.

Thanks again @to-aoki for reporting the issue. Let me know if you need any further help.