File size: 1,056 Bytes
3160316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()