azlan8289 commited on
Commit
8dc6ea9
·
verified ·
1 Parent(s): 6598fba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -1,30 +1,31 @@
1
  import gradio as gr
2
  import tensorflow as tf
 
3
 
4
- # Load your model
5
  model_path = 'fruitquality-1.0.h5'
6
  model = tf.keras.models.load_model(model_path)
7
 
8
- # Assuming your model expects images of size 224x224
9
- def preprocess_image(image):
10
- image = image.reshape(image, [300, 300])
11
- image = image / 255.0 # Normalize if your model expects this
12
- return image.numpy() # Return as numpy array
13
-
14
  def predict(image):
15
- processed_image = preprocess_image(image)
16
- prediction = model.predict(np.array([processed_image])) # Make prediction
17
- predicted_index = np.argmax(prediction, axis=1)[0]
18
- # Map your predicted index to class names
19
- class_names = [
20
- "Fresh Peaches", "Fresh Pomegranates", "Fresh Strawberries",
21
- "Rotten Peaches", "Rotten Pomegranates", "Rotten Strawberries"
22
- ]
 
 
 
 
23
  return class_names[predicted_index]
24
 
 
25
  iface = gr.Interface(fn=predict,
26
- inputs=gr.inputs.Image(),
27
- outputs="text",
28
  title="Fruit Quality Classifier",
29
  description="Upload an image of the fruit.")
30
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
+ import numpy as np
4
 
5
+ # Assuming you have the model loaded correctly as 'model'
6
  model_path = 'fruitquality-1.0.h5'
7
  model = tf.keras.models.load_model(model_path)
8
 
9
+ # Define the prediction function
 
 
 
 
 
10
  def predict(image):
11
+ # Preprocess the image here as needed
12
+ processed_image = tf.image.resize(image, (224, 224))
13
+ processed_image = processed_image / 255.0 # Normalize if necessary
14
+ processed_image = np.expand_dims(processed_image, axis=0) # Add batch dimension
15
+
16
+ predictions = model.predict(processed_image)
17
+ predicted_index = np.argmax(predictions, axis=1)[0]
18
+
19
+ # Define your class names
20
+ class_names = ["Fresh Peaches", "Fresh Pomegranates", "Fresh Strawberries",
21
+ "Rotten Peaches", "Rotten Pomegranates", "Rotten Strawberries"]
22
+
23
  return class_names[predicted_index]
24
 
25
+ # Update Gradio Interface creation to match Gradio 2.x syntax
26
  iface = gr.Interface(fn=predict,
27
+ inputs=gr.Image(shape=(224, 224)), # Corrected usage
28
+ outputs=gr.Text(),
29
  title="Fruit Quality Classifier",
30
  description="Upload an image of the fruit.")
31