Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import fastbook
|
3 |
+
fastbook.setup_book()
|
4 |
+
from fastai.vision.all import *
|
5 |
+
from fastbook import *
|
6 |
+
matplotlib.rc('image', cmap='Greys')
|
7 |
+
from fastai.vision.widgets import *
|
8 |
+
from ipywidgets import Button, HBox, VBox
|
9 |
+
import os
|
10 |
+
import shutil
|
11 |
+
|
12 |
+
learn = load_learner('model.pkl')
|
13 |
+
im_bb = PILImage.create('samp_bb.jpg')
|
14 |
+
im_lf = PILImage.create('samp_lf.jpg')
|
15 |
+
im_other = PILImage.create('samp_other.jpg')
|
16 |
+
|
17 |
+
categories = ('bb', 'lf', 'other')
|
18 |
+
def classify_image(img):
|
19 |
+
pred, idx, probs = learn.predict(img)
|
20 |
+
return dict(zip(categories, map(float, probs)))
|
21 |
+
|
22 |
+
image = gr.inputs.Image(shape=(50,50))
|
23 |
+
label = gr.outputs.Label()
|
24 |
+
examples = ['samp_lf.jpg', 'samp_other.jpg']
|
25 |
+
|
26 |
+
intf= gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
27 |
+
intf.launch(inline=False)
|