title: TypeError: expected str, bytes or os.PathLike object, not PngImageFile In Streamlit web app
body: <pre><code>import streamlit as st 
  from PIL import Image 
  import numpy as np
  from tensorflow.keras.models import load_model
  from tensorflow.keras.preprocessing.image import img_to_array, load_img
  import numpy as np
  import tensorflow as tf
  from pathlib import Path
  
  @st.cache(allow_output_mutation=True)
  def get_model():
          model = load_model('TSR.hdf5')
          print('Model Loaded')
          return model 
  
  sign_names = {
          0: 'Speed limit (20km/h)',
          1: 'Speed limit (30km/h)',
          2: 'Speed limit (50km/h)',
          3: 'Speed limit (60km/h)',
          4: 'Speed limit (70km/h)',
          5: 'Speed limit (80km/h)',
          6: 'End of speed limit (80km/h)',
          7: 'Speed limit (100km/h)',
          8: 'Speed limit (120km/h)',
          9: 'No passing',
          10: 'No passing for vehicles over 3.5 metric tons',
          11: 'Right-of-way at the next intersection',
          12: 'Priority road',
          13: 'Yield',
          14: 'Stop',
          15: 'No vehicles',
          16: 'Vehicles over 3.5 metric tons prohibited',
          17: 'No entry',
          18: 'General caution',
          19: 'Dangerous curve to the left',
          20: 'Dangerous curve to the right',
          21: 'Double curve',
          22: 'Bumpy road',
          23: 'Slippery road',
          24: 'Road narrows on the right',
          25: 'Road work',
          26: 'Traffic signals',
          27: 'Pedestrians',
          28: 'Children crossing',
          29: 'Bicycles crossing',
          30: 'Beware of ice/snow',
          31: 'Wild animals crossing',
          32: 'End of all speed and passing limits',
          33: 'Turn right ahead',
          34: 'Turn left ahead',
          35: 'Ahead only',
         }
  
  def predict(image):
          loaded_model = get_model()
          image = load_img(image, target_size=(30,30), color_mode = &quot;grayscale&quot;)
          image = img_to_array(image)
          image = image/255.0
          image = np.reshape(image,[1,30,30,1])
          classes = loaded_model.predict_classes(image)
          return classes
  
  st.title(&quot;Traffic Sign Classifier&quot;)
  uploaded_file = st.file_uploader(&quot;Choose an image...&quot;, type=&quot;png&quot;)
  
  if uploaded_file is not None:
  
          image=Image.open(uploaded_file)
          st.image(image, caption='Uploaded Image', use_column_width=True)
          st.write(&quot;&quot;)
          st.write(&quot;Result...&quot;)
          label = predict(image)
          label = label.item()
          res = sign_names.get(label)
          st.markdown(res)
  </code></pre>
  <p>This is my code and I do not know how to solve this error.please anyone help me regarding this.
  ERROR:</p>
  <pre><code>TypeError: expected str, bytes or os.PathLike object, not PngImageFile
  Traceback:
  File &quot;c:\users\kruna\appdata\local\programs\python\python39\lib\site-packages\streamlit\script_runner.py&quot;, line 333, in _run_script
      exec(code, module.__dict__)
  File &quot;K:\TrafficSignUpload\app.py&quot;, line 73, in &lt;module&gt;
      label = predict(image)
  File &quot;K:\TrafficSignUpload\app.py&quot;, line 57, in predict
      image = load_img(image, target_size=(30,30), color_mode = &quot;grayscale&quot;)
  File &quot;C:\Users\kruna\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\keras\preprocessing\image.py&quot;, line 295, in load_img
      return image.load_img(path, grayscale=grayscale, color_mode=color_mode,
  File &quot;C:\Users\kruna\AppData\Roaming\Python\Python39\site-packages\keras_preprocessing\image\utils.py&quot;, line 113, in load_img
      with open(path, 'rb') as f:
  </code></pre>
  <p>I loaded the model that I have trained before and made app.py file for web app with the use of streamlit ( Python library) but there is an error regarding image uploading may be I do not know what is is about, Help me in this.</p>