Spaces:
Runtime error
Runtime error
import gradio as gr | |
from huggingface_hub import login, from_pretrained_keras | |
import os | |
import numpy as np | |
import cv2 | |
login(os.environ["HF_TOKEN"]) | |
model = from_pretrained_keras("elsamueldev/cats-dogs") | |
def preprocess(img: np.array) -> np.array: | |
img = cv2.resize(img, (100, 100)) # resize to 100x100 | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale | |
img = img.reshape(100, 100, 1) # reshape to 100x100x1 | |
img = img / 255 # normalize | |
img = np.array([img]) # reshape to 1x100x100x1 | |
return img | |
def predict(img: np.array): | |
img = preprocess(img) | |
dog = model.predict(img)[0][0] | |
cat = 1 - dog | |
return {"dog": dog, "cat": cat} | |
gr.Interface( | |
fn=predict, | |
inputs="image", | |
outputs="label" | |
).launch() |