Dharma20 commited on
Commit
a72431b
·
verified ·
1 Parent(s): 3890b33

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %% ../hugging-space-model-app.ipynb 4
2
+ from fastai.vision.all import *
3
+ import gradio as gr
4
+
5
+ # %% ../hugging-space-model-app.ipynb 7
6
+ learn = load_learner('model1.pkl')
7
+
8
+ # %% ../hugging-space-model-app.ipynb 9
9
+ labels = ['Dog','Cat']
10
+ def classify_image(img):
11
+ img = PILImage.create(img)
12
+ pred,pred_idx,probs = learn.predict(img)
13
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
14
+
15
+ # %% ../hugging-space-model-app.ipynb 11
16
+ image = gr.components.Image()
17
+ label = gr.components.Label(show_label=True)
18
+ examples = ['dog.jpg','cat.jpg']
19
+
20
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
21
+ intf.launch(inline=False)