Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import platform
|
2 |
+
import pathlib
|
3 |
+
plt = platform.system()
|
4 |
+
pathlib.WindowsPath = pathlib.PosixPath
|
5 |
+
|
6 |
+
|
7 |
+
import requests
|
8 |
+
|
9 |
+
|
10 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
11 |
+
|
12 |
+
# %% auto 0
|
13 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'interface', 'classify_image']
|
14 |
+
|
15 |
+
# %% app.ipynb 1
|
16 |
+
from fastai.vision.all import *
|
17 |
+
import PIL.Image
|
18 |
+
PIL.Image.MAX_IMAGE_PIXELS = None
|
19 |
+
from PIL import Image
|
20 |
+
|
21 |
+
import gradio as gr
|
22 |
+
|
23 |
+
# %% app.ipynb 2
|
24 |
+
learn = load_learner('RetinalClassification.pkl')
|
25 |
+
|
26 |
+
# %% app.ipynb 3
|
27 |
+
categories=('cataract','diabetic_retinopathy','glaucoma','normal')
|
28 |
+
|
29 |
+
def classify_image(img):
|
30 |
+
pred,indx,probs=learn.predict(img)
|
31 |
+
return dict(zip(categories,map(float,probs)))
|
32 |
+
|
33 |
+
|
34 |
+
# %% app.ipynb 4
|
35 |
+
image=gr.inputs.Image(shape=(512,512))
|
36 |
+
label=gr.outputs.Label()
|
37 |
+
examples=['1.jpeg','10.png','11.png','12.jpeg','13.jpeg','14.jpeg','15.jpeg','16.jpeg','17.jpeg',
|
38 |
+
'18.jpeg','19.jpeg','2.jpeg','20.jpeg','21.jpg','22.jpg','23.jpg','3.jpeg','4.jpeg','5.jpeg',
|
39 |
+
'6.png','7.png','8.png','9.png']
|
40 |
+
|
41 |
+
|
42 |
+
interface=gr.Interface(fn=classify_image, inputs=image ,outputs=label)
|
43 |
+
interface.launch(inline=False)
|