Upload 3 files
Browse files- VGG.h5 +3 -0
- app.py +37 -0
- requirements.txt +4 -0
VGG.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:121b148fe3b53d5be7c04bff32abfcbb58ecab958aadedcc7952c7444014000a
|
| 3 |
+
size 62908016
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
from tensorflow.keras.preprocessing import image
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
model = load_model("VGG.h5")
|
| 9 |
+
|
| 10 |
+
# Define class names (order from your dataset's subfolders)
|
| 11 |
+
class_names = ['cat', 'dog', 'wild'] # Change if your folder names differ
|
| 12 |
+
|
| 13 |
+
IMG_SIZE = 224
|
| 14 |
+
|
| 15 |
+
def predict(img):
|
| 16 |
+
# Preprocess the image
|
| 17 |
+
img = img.resize((IMG_SIZE, IMG_SIZE))
|
| 18 |
+
img_array = image.img_to_array(img)
|
| 19 |
+
img_array = img_array / 255.0 # Rescale
|
| 20 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 21 |
+
|
| 22 |
+
# Predict
|
| 23 |
+
preds = model.predict(img_array)[0]
|
| 24 |
+
result = {class_names[i]: float(preds[i]) for i in range(len(class_names))}
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
+
# Build Gradio Interface
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=predict,
|
| 30 |
+
inputs=gr.Image(type="pil"),
|
| 31 |
+
outputs=gr.Label(num_top_classes=3),
|
| 32 |
+
title="Animal Face Classifier (VGG16)",
|
| 33 |
+
description="Upload an image of an animal face (cat, dog, or wild) and get the predicted class probabilities."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
numpy
|
| 4 |
+
Pillow
|