CoolFace
Apppublic

moazx/Dogs-vs-Cats-classification-with-Xception

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py52 linesDownload Raw Back to root
1import numpy as np2import cv23import gradio as gr4from tensorflow.keras.utils import img_to_array5from tensorflow.keras.models import load_model6 7# Load your pre-trained model8model = load_model(r'model.h5')9 10# Define the prediction function that takes an image as input and returns the predicted label11def predict_image(img):12    # Preprocess the image if needed13    x = img_to_array(img)14    x = cv2.resize(x, (299, 299), interpolation=cv2.INTER_AREA)15    x /= 25516    x = np.expand_dims(x, axis=0)17    image = np.vstack([x])18    # Make a prediction using your model19    prediction = model.predict(image)20    # Assuming your model returns probabilities, get the label with the highest probability21    predicted_label = "dog" if prediction > 0.5 else "cat"22    return predicted_label23 24# Define the Gradio Interface with the desired title and description25description_html = """26<p>This model was trained by Moaz Eldsouky You can find more about me here:</p>27<p>GitHub: <a href="https://github.com/MoazEldsouky">GitHub Profile</a></p>28<p>LinkedIn: <a href="https://www.linkedin.com/in/moaz-eldesouky-762288251/">LinkedIn Profile</a></p>29<p>Kaggle: <a href="https://www.kaggle.com/moazeldsokyx">Kaggle Profile</a></p>30<p>This model was trained to predict whether an image contains a cat or a dog.</p>31<p>You can see how this model was trained on the following Kaggle Notebook:</p>32<p><a href="https://www.kaggle.com/code/moazeldsokyx/dogs-vs-cats-classification-with-xception">Kaggle Notebook</a></p>33<p>Upload a photo to see how the model predicts!</p>34"""35 36# Example images for a dog and a cat37example_dog_image = "dog_.jpeg"38example_cat_image = "FELV-cat.jpg"39 40gr.Interface(41    fn=predict_image,42    inputs="image",43    outputs="text",44    title="Dogs vs Cats classification with Xception 🐶vs 😺",45    description=description_html,46    allow_flagging='never',47    examples=[48        [example_dog_image],  # Example image for a dog49        [example_cat_image],  # Example image for a cat50    ]51).launch()52