Looking for Hook to Capture Progress Bar Status for GUI #1689
Replies: 3 comments
-
i can only think of 2 possibilities: either edit source code to expose progress bar or write your own |
Beta Was this translation helpful? Give feedback.
-
fyi in case this is helpful, I haven't used it stqdm : 'stqdm is the simplest way to handle a progress bar in streamlit app' streamlit discussion board on stqdm |
Beta Was this translation helpful? Give feedback.
-
I was able to come up with a solution. its not idea but it is functional. The above is not a completely working program, but the target solution does work. The code is left for the reader to implement based on their needs. import streamlit as st
import sys, logging, time
# Create a custom Streamlit component to capture stdout and stderr
class StreamlitOutputRedirector:
def __init__(self, placeholder):
self.buffer = ""
self.placeholder = placeholder
def write(self, text):
# Define a keyword to selectively redirect
keyword_to_redirect = "frames/s]"
# Check if the keyword is present in the text
if keyword_to_redirect in text:
# Redirect text containing the keyword to Streamlit
# sys.__stdout__.write(text) # Testing
# Split the input string at each "|"
split_elements = text.split("|")
left = split_elements[0].strip() # contains percentage complete
right = split_elements[2].strip() # contains "frames/s" information
newText = left + " | " + right
self.setText(newText)
else:
# Print text without the keyword to the console
sys.__stdout__.write(text)
def flush(self):
# Display the captured output
# self.placeholder.text(self.buffer)
# self.buffer = ""
#Do nothing. The text is already written
a = 0
def clear(self):
# Clear the Streamlit screen by emptying the placeholder
self.placeholder.empty()
# self.flush() # Call flush after writing
def setText(self, newText):
# Write content into placeholder
# self.placeholder.write(newText) # normal writing
self.placeholder.write(f"###### {newText}") # markdown, write very small
def replacePlaceholder(self, newPlaceholder):
# Replace the exising placeholder
# The desired placeholder may not be initially known
self.placeholder = newPlaceholder
# Create an empty placeholder for dynamic content
output_placeholder = st.empty()
# Create an instance of the custom StreamlitOutputRedirector
output_redirector = StreamlitOutputRedirector(output_placeholder)
# Redirect stdout and stderr to the custom redirector
sys.stdout = output_redirector
sys.stderr = output_redirector
def transcribeAudio():
progress = st.sidebar.empty() # Create the desired placeholder for progress information
output_redirector.replacePlaceholder(progress) # Replace the existing placeholder
output_redirector.setText("0% complete") # Set the initial text
results = model.transcribe(tempTargetPath, fp16=False, word_timestamps = True, verbose=False)
# ***The progress bar will now automatically capture and update the "progress" place holder*** This doesn't work perfectly. The updates to the console are not capture perfectly and I don't understand why. I love Whisper! While this is targeted for Streamlit, I suspect this can be modified to work with other GUI interfaces I hope in the future, there will be a hook\callback so this type of workaround is unnecessary. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a Streamlit application that enables transcription of media dropped into the GUI.
When I click a button, I start the transcription process. All works as expected but I would like to surface the progress bar information that is available using the following, where verbose=False shows the progress bar
results = model.transcribe(tempTargetPath, fp16=False, word_timestamps = True, verbose=False)
Console output
100%|█████████████████████████████| 370639/370639 [03:47<00:00, 1625.89frames/s]
.
The above progress is going to the console but my program is GUI and does not directly have access to the console information. I did however redirect the console output.
.
Redirected console output
...
98%|#########7| 362652/370639 [03:36<00:04, 1636.68frames/s]
99%|#########8| 365340/370639 [03:38<00:03, 1635.98frames/s]
99%|#########9| 368164/370639 [03:40<00:01, 1601.73frames/s]
100%|##########| 370639/370639 [03:42<00:00, 1570.82frames/s]
100%|##########| 370639/370639 [03:42<00:00, 1668.54frames/s]
I have done a bit of hack above and redirected stdout and stderr to my program but this is not desirable, as all console output is redirected, not just the progress bar.
I am not redirecting to a file because then I would need to hunt for additional information or errors in the file versus where the user can see the information or errors.
Is there a hook\callback that can be used to capture the progress bar information?
Beta Was this translation helpful? Give feedback.
All reactions