feat: add option to make progress hook transient (#1264)

This commit is contained in:
Hervé BREDIN authored and GitHub committed 2023-02-16 21:17:08 +01:00
1 parent 2a9a892726
commit d4ff0bd23d
1 file changed
+10
+10
View File
@@ -51,6 +51,11 @@ def logging_hook(
class ProgressHook:
"""Hook to show progress of each internal step
Parameters
----------
transient: bool, optional
Clear the progress on exit. Defaults to False.
Example
-------
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization")
@@ -58,6 +63,10 @@ class ProgressHook:
output = pipeline(file, hook=hook)
"""
def __init__(self, transient: bool = False):
super().__init__()
self.transient = transient
def __enter__(self):
self.progress = Progress(
@@ -65,6 +74,7 @@ class ProgressHook:
BarColumn(),
TaskProgressColumn(),
TimeRemainingColumn(elapsed_when_finished=True),
transient=self.transient,
)
self.progress.start()
return self