Spaces:
Runtime error
Runtime error
import gradio as gr | |
import cv2 | |
from huggingface_hub import from_pretrained_keras | |
from skimage import io | |
ROWS, COLS = 150, 150 | |
model = from_pretrained_keras("carlosaguayo/cats_vs_dogs") | |
def process_image(img): | |
img = cv2.resize(img, (ROWS, COLS), interpolation=cv2.INTER_CUBIC) | |
img = img / 255.0 | |
img = img.reshape(1,ROWS,COLS,3) | |
prediction = model.predict(img)[0][0] | |
if prediction >= 0.5: | |
message = 'I am {:.2%} sure this is a Cat'.format(prediction) | |
else: | |
message = 'I am {:.2%} sure this is a Dog'.format(1-prediction) | |
return message | |
title = "Interactive demo: Classify cat vs dog" | |
description = "Simple Cat vs Dog classification" | |
article = "" | |
# examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]] | |
iface = gr.Interface(fn=process_image, | |
inputs=gr.inputs.Image(), | |
outputs=gr.outputs.Textbox(), | |
title=title, | |
description=description) | |
# article=article, | |
# examples=examples) | |
iface.launch() |