File size: 949 Bytes
2bfbe93
f3ef3b1
2bfbe93
 
 
 
7d5359f
2a384b6
2bfbe93
bffcb48
2a384b6
2bfbe93
 
0b2a0d9
 
 
 
2bfbe93
0b2a0d9
2bfbe93
 
 
0b2a0d9
 
2bfbe93
0b2a0d9
 
 
 
 
 
 
 
 
 
 
a1002e9
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
35
36
37
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)