AttributeError: 'NoneType' object has no attribute 'update' fastai and streamlit

Hello

I want to create an web app using streamlit that classify dogs but I can’t get it to work

I tried every trick in the book but I got nowhere, here is my code :

%%writefile app.py
from fastai.vision.widgets import *
from fastai.vision.all import *
from pathlib import Path
import streamlit as st
    
    class Predict:
        def __init__(self, filename):
            self.learn_inference = load_learner(Path()/filename)      
            self.img = self.get_image_from_upload()
            if self.img is not None:
              self.display_output()
              self.get_prediction()
                  
        @staticmethod
        def get_image_from_upload():
            uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg', 'jpg'])
            if uploaded_file is not None:
              return PILImage.create((uploaded_file))
            return None
        def display_output(self):
            st.image(self.img.to_thumb(500,500), caption='Uploaded Image')
        def get_prediction(self):
            if st.button('Classify') :            
              self.pred, self.pred_idx, self.probs=self.learn_inference.predict(self.img)
              st.write(f'Prediction: {self.pred}; Probability: {self.probs[pred_idx]:.04f}')
            else: 
                return st.write(f'Click the button to classify')
    
    
    if __name__=='__main__':
    
        file_name='dog.pkl'
    
        predictor = Predict(file_name)

After I compile

!streamlit run app.py & npx localtunnel --port 8501

and I click on classify
I get :

AttributeError: 'NoneType' object has no attribute 'update'

Any help would be much appreciated.
Thanks

Traceback

<IPython.core.display.HTML object>
2022-01-18 18:17:18.723 Traceback (most recent call last):
File “/usr/local/lib/python3.7/dist-packages/streamlit/script_runner.py”, line 379, in run_script
exec(code, module.dict)
File “/content/app.py”, line 38, in
Predict(file_name)
File “/content/app.py”, line 14, in init
self.get_prediction()
File “/content/app.py”, line 26, in get_prediction
self.pred, self.pred_idx, self.probs=self.learn_inference.predict(self.img)
File “/usr/local/lib/python3.7/dist-packages/fastai/learner.py”, line 266, in predict
inp,preds,
,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)
File “/usr/local/lib/python3.7/dist-packages/fastai/learner.py”, line 253, in get_preds
self._do_epoch_validate(dl=dl)
File “/usr/local/lib/python3.7/dist-packages/fastai/learner.py”, line 203, in _do_epoch_validate
with torch.no_grad(): self._with_events(self.all_batches, ‘validate’, CancelValidException)
File “/usr/local/lib/python3.7/dist-packages/fastai/learner.py”, line 163, in with_events
try: self(f’before
{event_type}’); f()
File “/usr/local/lib/python3.7/dist-packages/fastai/learner.py”, line 141, in call
def call(self, event_name): L(event_name).map(self._call_one)
File “/usr/local/lib/python3.7/dist-packages/fastcore/foundation.py”, line 155, in map
def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
File “/usr/local/lib/python3.7/dist-packages/fastcore/basics.py”, line 698, in map_ex
return list(res)
File “/usr/local/lib/python3.7/dist-packages/fastcore/basics.py”, line 683, in call
return self.func(*fargs, **kwargs)
File “/usr/local/lib/python3.7/dist-packages/fastai/learner.py”, line 145, in _call_one
for cb in self.cbs.sorted(‘order’): cb(event_name)
File “/usr/local/lib/python3.7/dist-packages/fastai/callback/core.py”, line 45, in call
if self.run and _run: res = getattr(self, event_name, noop)()
File “/usr/local/lib/python3.7/dist-packages/fastai/callback/progress.py”, line 26, in before_validate
def before_validate(self): self._launch_pbar()
File “/usr/local/lib/python3.7/dist-packages/fastai/callback/progress.py”, line 35, in _launch_pbar
self.pbar.update(0)
File “/usr/local/lib/python3.7/dist-packages/fastprogress/fastprogress.py”, line 56, in update
self.update_bar(0)
File “/usr/local/lib/python3.7/dist-packages/fastprogress/fastprogress.py”, line 76, in update_bar
else: self.on_update(val, f’{100 * val/self.total:.2f}% [{val}/{self.total} {elapsed_t}<{remaining_t}{end}]’)
File “/usr/local/lib/python3.7/dist-packages/fastprogress/fastprogress.py”, line 125, in on_update
if self.display: self.out.update(HTML(self.progress))
AttributeError: ‘NoneType’ object has no attribute 'update

Did you find a solution? I’m facing the same issue right now.

Hello

Sadly, I didn’t find any solution.

If you find something please fell free to contact me at drwalidos@yahoo.fr

Thank you and good luck