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