Skip to content

Progress bar not displaying when using 'print_progress=True' #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SirDaXll opened this issue Feb 5, 2025 · 7 comments
Open

Progress bar not displaying when using 'print_progress=True' #97

SirDaXll opened this issue Feb 5, 2025 · 7 comments

Comments

@SirDaXll
Copy link
Contributor

SirDaXll commented Feb 5, 2025

I noticed that Whisper uses tqdm to show a progress bar when verbose=False. In the whisper.cpp project, there's a function named print_progress for this purpose, which is also present in pywhispercpp inside constants.py under PARAMS_SCHEMA (also referenced in the API documentation).

However, when I try to use this functionality, I don't see any progress bar—only the final transcription result is returned.

I tried using in the command line:

pwcpp copy.mp3 -m medium --output-txt --print_realtime true --print_progress true

And in Python:

from pywhispercpp.model import Model

model = Model('tiny')
segments = model.transcribe('copia.mp3', language='es', print_progress=True, print_realtime=True)

print_realtime works fine and are in the same location as the other

I installed the package from the source, use Windows 11 and Python 1.12.6.

This functionality is currently supported in pywhispercpp or if additional configuration is required?

absadiki added a commit that referenced this issue Feb 7, 2025
fix(print_progress): print progress callback #97
@absadiki
Copy link
Owner

absadiki commented Feb 7, 2025

Thanks @SirDaXll, for reporting the issue,

I noticed that print_progress now requires a progress callback, likely due to recent changes in whispercpp, that's why you didn't see anything. I tried to add a default callback with a simple message in case print_progress is True, but you can override this by defining your own custom progress_callback:

res = model.transcribe(media="audio.mp3", print_progress=True, progress_callback=lambda progress: print(progress))

Please pull the latest commit and try again. Let me know if you have any further issues.

@SirDaXll
Copy link
Contributor Author

SirDaXll commented Feb 7, 2025

@absadiki What seems most relevant to me about the output is the time elapsed/time remaining in progress (how output should be: 35%|███▌ | 5588/15901 [00:17<00:31, 326.60frames/s]), although the most important thing is to know that the transcription is progressing, so that's great. If you can figure it out completely, I'd be more grateful than I already am, and if I have time to review it, I'll share it as soon as I can. For now, thanks for the solution!

@absadiki
Copy link
Owner

absadiki commented Feb 7, 2025

@SirDaXll, if you are just looking for a progress bar like effect, you can achieve that easily by using tqdm and the progress_callback I mentioned earlier:

with tqdm(total=100) as pbar:
    res = model.transcribe(media="audio.mp3",
                       print_progress=True,
                       progress_callback=lambda progress: (setattr(pbar, 'n', progress), pbar.refresh()),
                       )

however, whisper.cpp does not provide a progress bar with elapsed/time remaining AFAIK.

@SirDaXll
Copy link
Contributor Author

@absadiki It is a good solution in the absence of the progress bar, it only works as a reference, since in the absence of having a function that obtains the total frames of the audio and indicates it to tqdm (as Whisper does), the progress will not be precise. I tried the frames thing with pydub, I still didn't get good results, so for the moment I'll stick with what there is.

@SirDaXll
Copy link
Contributor Author

@absadiki After the update I did not try to execute from the command line, only from a .py file, and now I have an error when receiving the parameters. I tried in 2 computers, with and without venv, just to check.

>pwcpp copy.mp3 -m small -otxt

PyWhisperCpp
A simple Command Line Interface to test the package
Version: 1.3.1.dev12+ga484dc2
====================================================

whisper_init_from_file_with_params_no_state: loading model from 'C:\Users\myuser\AppData\Local\pywhispercpp\pywhispercpp\models\ggml-small.bin'
whisper_init_with_params_no_state: use gpu    = 1
whisper_init_with_params_no_state: flash attn = 0
whisper_init_with_params_no_state: gpu_device = 0
whisper_init_with_params_no_state: dtw        = 0
whisper_model_load: loading model
whisper_model_load: n_vocab       = 51865
whisper_model_load: n_audio_ctx   = 1500
whisper_model_load: n_audio_state = 768
whisper_model_load: n_audio_head  = 12
whisper_model_load: n_audio_layer = 12
whisper_model_load: n_text_ctx    = 448
whisper_model_load: n_text_state  = 768
whisper_model_load: n_text_head   = 12
whisper_model_load: n_text_layer  = 12
whisper_model_load: n_mels        = 80
whisper_model_load: ftype         = 1
whisper_model_load: qntvr         = 0
whisper_model_load: type          = 3 (small)
whisper_model_load: adding 1608 extra tokens
whisper_model_load: n_langs       = 99
whisper_model_load:      CPU total size =   487.01 MB
whisper_model_load: model size    =  487.01 MB
whisper_init_state: kv self size  =   56.62 MB
whisper_init_state: kv cross size =   56.62 MB
whisper_init_state: kv pad  size  =    4.72 MB
whisper_init_state: compute buffer (conv)   =   22.41 MB
whisper_init_state: compute buffer (encode) =  280.07 MB
whisper_init_state: compute buffer (cross)  =    6.18 MB
whisper_init_state: compute buffer (decode) =   97.27 MB
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Python312\Scripts\pwcpp.exe\__main__.py", line 7, in <module>
  File "C:\Users\myuser\AppData\Roaming\Python\Python312\site-packages\pywhispercpp\examples\main.py", line 96, in main
    run(args)
  File "C:\Users\myuser\AppData\Roaming\Python\Python312\site-packages\pywhispercpp\examples\main.py", line 48, in run
    logging.info(f"System info: n_threads = {m.get_params()['n_threads']} | Processors = {args.processors} "
                                             ^^^^^^^^^^^^^^
  File "C:\Users\myuser\AppData\Roaming\Python\Python312\site-packages\pywhispercpp\model.py", line 169, in get_params
    res[param] = getattr(self._params, param)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Unable to convert function return value to a Python type! The signature was
        (self: _pywhispercpp.whisper_full_params) -> function

@absadiki
Copy link
Owner

@SirDaXll, it seems that the Python getattr function is having issues with converting the new progress_callback function I added in the previous commit, I think we can ignore it.
Give it a try now; hopefully, it is fixed.

@SirDaXll
Copy link
Contributor Author

@absadiki With that last commit I found the problem that now some parameters entered by the command prompt did not work (in the .py file there are no problems), so I went into the model.py code to find the problem, locating different log captures in the terminal and see what happens, well I found that it captured the parameters but reset them to certain default values ​​in "_init_model", so I commented a line and the problem was solved. In the pull request I better describe what happened.

def _init_model(self) -> None:
    """
    Private method to initialize the method from the bindings, it will be called automatically from the __init__
    :return:
    """
    logger.info("Initializing the model ...")
    with utils.redirect_stderr(to=self.redirect_whispercpp_logs_to):
        self._ctx = pw.whisper_init_from_file(self.model_path)
        # Don't set the params to the default ones here, as it will overwrite the user's params
        # self._params = pw.whisper_full_default_params(pw.whisper_sampling_strategy.WHISPER_SAMPLING_GREEDY)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants