GGOSinonD commited on
Commit
a4207c1
·
1 Parent(s): aa75539

First commit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+
Model/cats_dogs_cnn_batchnorm.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45e6d263e65cbec66d3c79becf5865fb41be1f405fee97b4d9c2e39986685297
3
+ size 39753104
Model/cats_dogs_vgg.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d0d8c4bd8b8d2614ae47fccbb87f7e0cd4dc8c94e1f304af8a926c358295642
3
+ size 84128112
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ import tensorflow
5
+ from PIL import Image
6
+
7
+ model = load_model("Model\\cats_dogs_cnn_batchnorm.h5")
8
+
9
+ # Function to preprocess image
10
+ def preprocess_image(img):
11
+ img = img.resize((128, 128)) # Resize to match model input size
12
+ img = np.array(img) / 255.0 # Normalize pixel values
13
+ img = np.expand_dims(img, axis=0) # Add batch dimension
14
+ return img
15
+
16
+ # Function to predict class
17
+ def predict(img):
18
+ img = preprocess_image(img)
19
+ prediction = model.predict(img)[0][0] # Get model output
20
+
21
+ # Convert output to class label
22
+ label = "Cat 🐱" if prediction > 0.5 else "Dog 🐶" # Cat is labeled 0 and Dog is labeled 1
23
+ confidence = round(float(prediction * 100), 2) if prediction > 0.5 else round(float((1 - prediction) * 100), 2)
24
+
25
+ return f"{label} (Confidence: {confidence}%)"
26
+
27
+ # Gradio UI
28
+ demo = gr.Interface(
29
+ fn=predict,
30
+ inputs=gr.Image(type="pil"), # Accepts image input
31
+ outputs=gr.Textbox(label="Prediction"),
32
+ title="Cat vs Dog Classifier (Golden Owl code test)",
33
+ description="Upload an image to predict if it's a cat or a dog."
34
+ )
35
+
36
+ # Run the app
37
+ if __name__ == "__main__":
38
+ demo.launch()