dnth commited on
Commit
b159813
·
1 Parent(s): c4e47c7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+
4
+ # import skimage
5
+
6
+ learn = load_learner("models/learner.pkl")
7
+
8
+ labels = learn.dls.vocab
9
+
10
+
11
+ def predict(img):
12
+ img = PILImage.create(img)
13
+ pred, pred_idx, probs = learn.predict(img)
14
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
15
+
16
+
17
+ import os
18
+
19
+ for root, dirs, files in os.walk(r"sample_images/"):
20
+ for filename in files:
21
+ print(filename)
22
+
23
+ title = "NSWX Electrode Classifier"
24
+ description = "Ok, KIV, NG"
25
+ interpretation = "default"
26
+ examples = ["sample_images/" + file for file in files]
27
+ article = "<p style='text-align: center'><a href='https://dicksonneoh.com/' target='_blank'>Blog post</a></p>"
28
+ enable_queue = True
29
+
30
+ gr.Interface(
31
+ fn=predict,
32
+ inputs=gr.inputs.Image(shape=(460, 460)),
33
+ outputs=gr.outputs.Label(num_top_classes=5),
34
+ title=title,
35
+ description=description,
36
+ article=article,
37
+ examples=examples,
38
+ interpretation=interpretation,
39
+ enable_queue=enable_queue,
40
+ capture_session=True
41
+ ).launch(share=True, server_name="0.0.0.0")