shallou commited on
Commit
f85dff3
·
verified ·
1 Parent(s): 72a0a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -8,12 +8,10 @@ import os
8
  # Function to load the model
9
  @st.cache_resource
10
  def load_model():
11
- model_path = 'path_to_your_saved_model.h5' # Ensure this path is correct relative to your deployment setup
12
-
13
  if not os.path.isfile(model_path):
14
  st.error(f"Model file not found: {model_path}")
15
  return None
16
-
17
  try:
18
  model = tf.keras.models.load_model(model_path)
19
  st.success("Model loaded successfully!")
@@ -25,8 +23,8 @@ def load_model():
25
  # Function to preprocess the image
26
  def preprocess_image(image):
27
  image = np.array(image.convert('RGB'))
28
- image = cv2.resize(image, (224, 224)) # Resize the image to the input shape required by your model
29
- image = image / 255.0 # Normalize the image
30
  image = np.expand_dims(image, axis=0)
31
  return image
32
 
@@ -56,7 +54,7 @@ def main():
56
  st.write("Classifying...")
57
  try:
58
  prediction = predict(image, model)
59
- predicted_class = np.argmax(prediction, axis=1)[0] # Adjust based on your model's output
60
  st.write(f"Predicted class: {predicted_class}")
61
  except Exception as e:
62
  st.error(f"Error in prediction: {e}")
 
8
  # Function to load the model
9
  @st.cache_resource
10
  def load_model():
11
+ model_path = 'models/my_model.h5' # Path relative to the script
 
12
  if not os.path.isfile(model_path):
13
  st.error(f"Model file not found: {model_path}")
14
  return None
 
15
  try:
16
  model = tf.keras.models.load_model(model_path)
17
  st.success("Model loaded successfully!")
 
23
  # Function to preprocess the image
24
  def preprocess_image(image):
25
  image = np.array(image.convert('RGB'))
26
+ image = cv2.resize(image, (224, 224))
27
+ image = image / 255.0
28
  image = np.expand_dims(image, axis=0)
29
  return image
30
 
 
54
  st.write("Classifying...")
55
  try:
56
  prediction = predict(image, model)
57
+ predicted_class = np.argmax(prediction, axis=1)[0]
58
  st.write(f"Predicted class: {predicted_class}")
59
  except Exception as e:
60
  st.error(f"Error in prediction: {e}")