Zakia commited on
Commit
8c6634a
1 Parent(s): 95e71df

add app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Bismillahir Rahmaanir Raheem
2
+ # Almadadh Ya Gause Radi Allahu Ta'alah Anh - Ameen
3
+
4
+
5
+ from fastai.vision.all import *
6
+ import gradio as gr
7
+
8
+
9
+ def is_cat(x):
10
+ return x[0].isupper()
11
+
12
+
13
+
14
+ # load the trained fast ai model for predictions
15
+ learn = load_learner('model.pkl')
16
+
17
+
18
+ # define the function to call
19
+ categories = ('Dog', 'Cat')
20
+
21
+ def predict(img):
22
+ pred, idx, probs = learn.predict(img)
23
+ return dict(zip(categories, map(float, probs)))
24
+
25
+
26
+ title = "CAT PREDICTOR"
27
+
28
+ description = "A cat predictor model trained on the Pets dataset with fastai. Created as a demo for Gradio and Hugging Face spaces."
29
+
30
+
31
+ article = "<p style='text-align: center'><span style='font-size: 15pt;'>CAT_PREDICTOR. 2022. </span></p>"
32
+
33
+
34
+ image = gr.inputs.Image(shape=(192, 192))
35
+ label = gr.outputs.Label()
36
+ examples = ['chapter1_cat_example.jpg']
37
+ interpretation = 'default'
38
+ enable_queue = True
39
+
40
+
41
+
42
+
43
+ iface = gr.Interface(
44
+ fn=predict,
45
+ title=title,
46
+ description=description,
47
+ article=article,
48
+ inputs=image,
49
+ outputs=label,
50
+ #theme="grass",
51
+ examples=examples,
52
+ interpretation=interpretation,
53
+ enable_queue=enable_queue
54
+ )
55
+
56
+
57
+
58
+ iface.launch(inline=False)