Vinit710 commited on
Commit
690eb2b
·
verified ·
1 Parent(s): 20aca7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import gradio as gr
2
  from tensorflow.keras.models import load_model
3
- from tensorflow.keras.preprocessing.image import img_to_array, load_img
4
- import numpy as np
5
  from PIL import Image
 
6
 
7
- # Load your model (using a relative path)
8
- model_path = "cats_and_dogs_classifier.h5"
9
- model = load_model(model_path)
10
 
 
11
  def predict(image):
12
- # Resize image to match model's expected sizing
13
  img = image.resize((150, 150))
14
  # Convert image to array and expand dimensions to fit model input requirements
15
  img_array = img_to_array(img)
@@ -21,12 +21,5 @@ def predict(image):
21
  return class_label
22
 
23
  # Create a Gradio interface
24
- iface = gr.Interface(fn=predict,
25
- inputs=gr.inputs.Image(type='pil', label="Upload a photo of a cat or dog"),
26
- outputs="text",
27
- title="Cat or Dog Classifier",
28
- description="Upload an image of a cat or dog to classify it.")
29
-
30
- if __name__ == "__main__":
31
- iface.launch()
32
-
 
1
  import gradio as gr
2
  from tensorflow.keras.models import load_model
3
+ from tensorflow.keras.preprocessing.image import img_to_array
 
4
  from PIL import Image
5
+ import numpy as np
6
 
7
+ # Load your model
8
+ model = load_model('cats_and_dogs_classifier.h5')
 
9
 
10
+ # Define prediction function
11
  def predict(image):
12
+ # Resize image to match model's expected sizing (150x150 pixels)
13
  img = image.resize((150, 150))
14
  # Convert image to array and expand dimensions to fit model input requirements
15
  img_array = img_to_array(img)
 
21
  return class_label
22
 
23
  # Create a Gradio interface
24
+ interface = gr.Interface(fn=predict, inputs="image", outputs="text")
25
+ interface.launch()