Download app.py from Peter10355/Classification_Dogs_and_Cats: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/Peter10355/Classification_Dogs_and_Cats/resolve/main/app.py
- Command line
-
hf download hf://spaces/Peter10355/Classification_Dogs_and_Cats/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Peter10355/Classification_Dogs_and_Cats/resolve/main/app.py
949 Bytes
| from keras.models import load_model | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import cv2 | |
| import tensorflow as tf | |
| import gradio as gr | |
| import torch | |
| import torch.nn as nn | |
| model = torch.load('model_cat_dog_torch') | |
| labels = ["Cat", "Doggggy"] | |
| def predict(image): | |
| image_size = (64, 64) | |
| image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
| image = cv2.resize(image, image_size) | |
| if image[0, 1, 1] > 1: | |
| image = image / 255.0 | |
| image = np.array(image, dtype='float32') | |
| image = np.expand_dims(image, axis=0) | |
| predictions = model.predict(image)[0] | |
| return {labels[i]: float(predictions[i]) for i in range(len(labels))} | |
| image = gr.Image(label="Upload a photo of a cat or dog") | |
| label = gr.Label() | |
| gr.Interface(fn=predict, inputs=image, outputs=label, title='Cats Vs Dogs',theme='peach',live= True).launch(share= True) |