File size: 779 Bytes
88032fb
52074fd
 
 
 
 
 
 
 
 
 
88032fb
 
 
 
52074fd
 
 
 
 
 
 
 
 
 
 
94dd6fa
52074fd
 
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
import gradio as gr
from fastai.vision.all import *
import pathlib
import os
from PIL import Image

temp = pathlib.PosixPath
if os.name == 'nt':
    pathlib.PosixPath = pathlib.WindowsPath

def is_cat(x): return x[0].isupper() 

def greet(name):
    return "Hello " + name + "!!"

learner = load_learner('model.pkl')
    
categories = ('Dog', "Cat")

def classify_image(img):
    resized_image = img.resize((192, 192))  # Resize here manually
    prediction, index, probs = learner.predict(resized_image)
    return dict(zip(categories,map(float,probs)))

image = gr.Image(type="pil")
label = gr.Label()
examples = ['samples/cute_dog.jpg',"samples/cat_graffity.jpg"]
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)