File size: 2,011 Bytes
918e4f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
import cv2
import gradio as gr
from tensorflow.keras.utils import img_to_array
from tensorflow.keras.models import load_model

# Load your pre-trained model
model = load_model(r'model.h5')

# Define the prediction function that takes an image as input and returns the predicted label
def predict_image(img):
    # Preprocess the image if needed
    x = img_to_array(img)
    x = cv2.resize(x, (299, 299), interpolation=cv2.INTER_AREA)
    x /= 255
    x = np.expand_dims(x, axis=0)
    image = np.vstack([x])
    # Make a prediction using your model
    prediction = model.predict(image)
    # Assuming your model returns probabilities, get the label with the highest probability
    predicted_label = "dog" if prediction > 0.5 else "cat"
    return predicted_label

# Define the Gradio Interface with the desired title and description
description_html = """
<p>This model was trained by Moaz Eldsouky You can find more about me here:</p>
<p>GitHub: <a href="https://github.com/MoazEldsouky">GitHub Profile</a></p>
<p>LinkedIn: <a href="https://www.linkedin.com/in/moaz-eldesouky-762288251/">LinkedIn Profile</a></p>
<p>Kaggle: <a href="https://www.kaggle.com/moazeldsokyx">Kaggle Profile</a></p>
<p>This model was trained to predict whether an image contains a cat or a dog.</p>
<p>You can see how this model was trained on the following Kaggle Notebook:</p>
<p><a href="https://www.kaggle.com/code/moazeldsokyx/dogs-vs-cats-classification-with-xception">Kaggle Notebook</a></p>
<p>Upload a photo to see how the model predicts!</p>
"""

# Example images for a dog and a cat
example_dog_image = "dog_.jpeg"
example_cat_image = "FELV-cat.jpg"

gr.Interface(
    fn=predict_image,
    inputs="image",
    outputs="text",
    title="Dogs vs Cats classification with Xception 🐶vs 😺",
    description=description_html,
    allow_flagging='never',
    examples=[
        [example_dog_image],  # Example image for a dog
        [example_cat_image],  # Example image for a cat
    ]
).launch()