miwojc commited on
Commit
a7c737f
1 Parent(s): 2a46306

Create new file

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ from huggingface_hub import from_pretrained_fastai
4
+
5
+ repo_id = "hugginglearners/brain-tumor-detection-mri"
6
+ learn = from_pretrained_fastai(repo_id)
7
+ labels = learn.dls.vocab
8
+
9
+ def predict(img):
10
+ img = PILImage.create(img)
11
+ _pred, _pred_w_idx, probs = learn.predict(img)
12
+ # gradio doesn't support tensors, so converting to float
13
+ labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
14
+ return labels_probs
15
+
16
+ interface_options = {
17
+ "title": "Brain tumor detection for MRI images",
18
+ "description": "For reference only. Should **not** be used for medical diagnosis",
19
+ "interpretation": "default",
20
+ "layout": "horizontal",
21
+ # Audio from validation file
22
+ # "examples": [
23
+ # "100098.jpg",
24
+ # "100002.jpg",
25
+ # "100048.jpg"
26
+ # ],
27
+ "allow_flagging": "never",
28
+ }
29
+
30
+ demo = gr.Interface(
31
+ fn=predict,
32
+ inputs=gr.inputs.Image(shape=(480, 480)),
33
+ outputs=gr.outputs.Label(num_top_classes=3),
34
+ **interface_options,
35
+ )
36
+
37
+ launch_options = {
38
+ "enable_queue": True,
39
+ "share": False,
40
+ }
41
+
42
+ demo.launch(**launch_options)