File size: 1,314 Bytes
8c6634a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c16f01
8c6634a
e4d849f
8c6634a
 
1c16f01
8c6634a
 
1c16f01
8c6634a
1c16f01
 
 
 
 
 
 
0d62753
9722dd1
1c16f01
8c6634a
 
 
 
 
 
 
 
 
 
 
 
 
468c941
8c6634a
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Bismillahir Rahmaanir Raheem 
# Almadadh Ya Gause Radi Allahu Ta'alah Anh - Ameen 


from fastai.vision.all import *
import gradio as gr


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


# load the trained fast ai model for predictions
learn = load_learner('model.pkl')


# define the function to call
categories = ('Dog', 'Cat') 

def predict(img):
	pred, idx, probs = learn.predict(img)
	return dict(zip(categories, map(float, probs)))
	
	
title = "Cat or Dog Predictor"

description = "A cat or dog predictor model trained on the Pets dataset using ResNet18 via <a href='http://www.fast.ai/' target='_blank'>fast.ai</a>."


article = "<p style='text-align: center'><span style='font-size: 15pt;'>Cat or Dog Predictor. Zakia Salod. 2022. </span></p>"


image = gr.inputs.Image(shape=(512, 512))
label = gr.outputs.Label()
examples = [
             ['cat1.jpg'],
			 ['dog1.jpg'],
			 ['cat2.jpg'],
			 ['dog2.jpg'],
			 ['cat3.jpg'],
			 ['dog3.jpg'],
			 ['cat4.jpg'],
			 ['dog4.jpg'],
		   ]
interpretation = 'default'
enable_queue = True 




iface = gr.Interface(
		fn=predict, 
		title=title, 
		description=description, 
		article=article,
		inputs=image, 
		outputs=label,
		theme="default",
		examples=examples,
		interpretation=interpretation,
		enable_queue=enable_queue
)



iface.launch(inline=False)