sudip2003 commited on
Commit
49619a7
·
verified ·
1 Parent(s): 52c96a9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ import numpy as np
5
+
6
+ # Load the trained model
7
+ model = tf.keras.models.load_model('cat_dog_classifier_vgg16.h5')
8
+
9
+ # Define a function to make predictions
10
+ def predict_image(img):
11
+ # Preprocess the image
12
+ img = img.resize((224, 224))
13
+ img_array = image.img_to_array(img)
14
+ img_array = np.expand_dims(img_array, axis=0)
15
+ img_array = img_array / 255.0
16
+
17
+ # Make a prediction
18
+ prediction = model.predict(img_array)
19
+ if prediction[0] < 0.5:
20
+ return "Cat"
21
+ else:
22
+ return "Dog"
23
+
24
+ # Create the Gradio interface
25
+ iface = gr.Interface(
26
+ fn=predict_image,
27
+ inputs=gr.inputs.Image(type="pil"),
28
+ outputs="text",
29
+ title="Cat and Dog Classifier",
30
+ description="Upload an image of a cat or a dog and the model will classify it.",
31
+ examples=["cat_example.jpg", "dog_example.jpg"]
32
+ )
33
+
34
+ # Launch the interface
35
+ iface.launch()