ML610 commited on
Commit
5b7eae7
Β·
1 Parent(s): 110eac0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import fastai
3
+
4
+ learn = load_learner('model.pkl')
5
+
6
+ labels = learn.dls.vocab
7
+
8
+ def predict(imgPath):
9
+ img = PILImage.create(imgPath)
10
+ pred,pred_idx,probs = learn.predict(img)
11
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
+
13
+ title = 'Butterflies vs Moths'
14
+ description = 'A basic app which checks whether the image uploaded by you is of a butterfly or a moth!'
15
+ examples = ['butterfly.jpg', 'moth.jpg']
16
+
17
+ UI = gr.Interface(
18
+ fn=predict,
19
+ inputs=gr.inputs.Image(shape=(512,512)),
20
+ outputs=gr.outputs.Label(num_top_classes=3),
21
+ title=title,
22
+ description=description,
23
+ examples=examples
24
+ )
25
+
26
+ UI.launch()