azlan8289 commited on
Commit
fa42fb9
·
verified ·
1 Parent(s): a4d21b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -4,7 +4,7 @@ from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
  # Load your Keras model
7
- model = load_model('vege_classifier_model.h5')
8
 
9
  # Define the updated classes
10
  classes = [
@@ -16,10 +16,10 @@ classes = [
16
  # Define a prediction function
17
  def predict_image(img):
18
  # Preprocess the image to fit the model's input requirements
19
- img = img.resize((224, 224)) # Resize image to 224x224 (adjust if your model expects a different size)
20
  img_array = image.img_to_array(img)
21
  img_array = np.expand_dims(img_array, axis=0) # Create a batch
22
- img_array /= 255.0 # Model expects pixels to be in [0, 1]
23
 
24
  # Predict
25
  predictions = model.predict(img_array)
@@ -28,12 +28,11 @@ def predict_image(img):
28
  # Return the class name
29
  return classes[predicted_class[0]]
30
 
31
- # Create a Gradio interface
32
  iface = gr.Interface(fn=predict_image,
33
- inputs=gr.inputs.Image(shape=(224, 224)),
34
- outputs="text",
35
  title="Vegetable Image Classifier",
36
  description="Classify images of various vegetables into 15 categories: Bean, Bitter Gourd, Bottle Gourd, Brinjal, Broccoli, Cabbage, Capsicum, Carrot, Cauliflower, Cucumber, Papaya, Potato, Pumpkin, Radish, Tomato.")
37
 
38
- if __name__ == "__main__":
39
- iface.launch()
 
4
  import numpy as np
5
 
6
  # Load your Keras model
7
+ model = load_model('model.h5')
8
 
9
  # Define the updated classes
10
  classes = [
 
16
  # Define a prediction function
17
  def predict_image(img):
18
  # Preprocess the image to fit the model's input requirements
19
+ img = img.resize((224, 224)) # Assume the model expects 224x224 images
20
  img_array = image.img_to_array(img)
21
  img_array = np.expand_dims(img_array, axis=0) # Create a batch
22
+ img_array /= 255.0 # Normalize the image to [0, 1]
23
 
24
  # Predict
25
  predictions = model.predict(img_array)
 
28
  # Return the class name
29
  return classes[predicted_class[0]]
30
 
31
+ # Create a simplified Gradio interface
32
  iface = gr.Interface(fn=predict_image,
33
+ inputs="image",
34
+ outputs="label",
35
  title="Vegetable Image Classifier",
36
  description="Classify images of various vegetables into 15 categories: Bean, Bitter Gourd, Bottle Gourd, Brinjal, Broccoli, Cabbage, Capsicum, Carrot, Cauliflower, Cucumber, Papaya, Potato, Pumpkin, Radish, Tomato.")
37
 
38
+ if __name__ == "__main__"