Hi, I have a function that runs some heavy computation to produce an image,
and i want to display the image with a slider to adjust the brightness.
like this :
def AdjustBrightness(image, plotpath): ## -- Brightness adjustments -- ShiftBy = st.slider('Brightness adjustments') ## -- Save image -- plt.figure(); librosa.display.specshow(image + float(ShiftBy)) plt.savefig(plotpath) ## -- Display image -- image = Image.open(plotpath) st.image(image, caption='Spectrogram & Onset', use_column_width=True) plotpath = "plot.png" image = SomeHeavyComputation() AdjustBrightness(image, plotpath)
However everytime i adjust the slider, the
SomeHeavyComputation() is re-ran, which takes up alot of time.
How do i prevent the earlier computations, and only re-run
AdjustBrightness() when i adjust the slider?