shallou commited on
Commit
6386a8e
·
verified ·
1 Parent(s): 77368f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -1,15 +1,18 @@
1
  import streamlit as st
2
- import pandas as pd
3
  import numpy as np
4
  import cv2
5
  from PIL import Image
6
  import tensorflow as tf
7
 
8
  # Function to load the model
9
- @st.cache_resource
10
  def load_model():
11
- model = tf.keras.models.load_model('path_to_your_saved_model.h5') # Provide the path to your model
12
- return model
 
 
 
 
13
 
14
  # Function to preprocess the image
15
  def preprocess_image(image):
@@ -32,6 +35,10 @@ def main():
32
 
33
  model = load_model()
34
 
 
 
 
 
35
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
36
  if uploaded_file is not None:
37
  image = Image.open(uploaded_file)
@@ -41,7 +48,9 @@ def main():
41
  st.write("Classifying...")
42
  prediction = predict(image, model)
43
 
44
- st.write(f"Predicted class: {np.argmax(prediction)}") # Update with your model's prediction logic
 
 
45
 
46
  if __name__ == "__main__":
47
  main()
 
1
  import streamlit as st
 
2
  import numpy as np
3
  import cv2
4
  from PIL import Image
5
  import tensorflow as tf
6
 
7
  # Function to load the model
8
+ @st.cache
9
  def load_model():
10
+ try:
11
+ model = tf.keras.models.load_model('path_to_your_saved_model.h5') # Provide the path to your model
12
+ return model
13
+ except Exception as e:
14
+ st.error(f"Error loading model: {e}")
15
+ return None
16
 
17
  # Function to preprocess the image
18
  def preprocess_image(image):
 
35
 
36
  model = load_model()
37
 
38
+ if model is None:
39
+ st.write("Model could not be loaded.")
40
+ return
41
+
42
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
43
  if uploaded_file is not None:
44
  image = Image.open(uploaded_file)
 
48
  st.write("Classifying...")
49
  prediction = predict(image, model)
50
 
51
+ # Adjust based on your model's output
52
+ predicted_class = np.argmax(prediction, axis=1)[0] # Assuming your model outputs probabilities for each class
53
+ st.write(f"Predicted class: {predicted_class}")
54
 
55
  if __name__ == "__main__":
56
  main()