dag101 commited on
Commit
62911d0
·
1 Parent(s): 237cc09
Files changed (1) hide show
  1. app.py +23 -28
app.py CHANGED
@@ -1,56 +1,51 @@
1
- #Importing necessary libraries
2
  import gradio as gr
3
  from fastai.vision.all import *
4
  from sklearn.metrics import roc_auc_score
5
 
6
- #Define dependent functions
7
- def get_x(row): return Path(str(path/f"{row['rootname']}_small"/f"{row['ID']}") + ".png")
8
  def get_y(row): return row["LABEL"]
9
-
10
  def auroc_score(input, target):
11
  input, target = input.cpu().numpy()[:,1], target.cpu().numpy()
12
  return roc_auc_score(target, input)
13
 
14
- #Load the model
15
- learn = load_learner("export.pkl")
16
 
17
- #Identify labels from the dataloaders class
18
  labels = ["Negative", "Positive"]
19
 
20
- #Define function for making prediction
21
  def predict(img):
22
- img = PILImage.create(img)
23
  pred, idx, probs = learn.predict(img)
24
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
25
 
26
- #Custom CSS
27
  custom_css = """
28
- body, button {
29
- background-color: #00FBB9;
30
- }
31
-
32
  button {
33
- color: #333;
34
- }
35
-
36
- p, span {
37
  color: #333;
 
 
 
38
  }
39
- """
40
 
41
- #Customizing the gradio interface
42
- title = "Ethiopian based Tuberculosis(TB) model"
43
- description = """Model to detect TB from chest x-rays"""
 
44
 
 
 
 
45
  examples = ['patient1.png', 'patient2.png', 'patient3.png']
46
- enable_queue=True
47
 
48
- #Launching the gradio interface
49
- gr.Interface(fn=predict,
50
- inputs=gr.inputs.Image(shape=(512, 512)),
51
- outputs=gr.outputs.Label(num_top_classes=1),
52
  title=title,
53
  description=description,
54
  examples=examples,
55
- enable_queue=enable_queue,
56
  css=custom_css).launch(inline=False)
 
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
  from sklearn.metrics import roc_auc_score
4
 
5
+ # Model functions
6
+ def get_x(row): return Path(str(path/f"{row['rootname']}_small"/f"{row['ID']}") + ".png")
7
  def get_y(row): return row["LABEL"]
 
8
  def auroc_score(input, target):
9
  input, target = input.cpu().numpy()[:,1], target.cpu().numpy()
10
  return roc_auc_score(target, input)
11
 
12
+ # Load model
13
+ learn = load_learner("export.pkl")
14
 
15
+ # Labels
16
  labels = ["Negative", "Positive"]
17
 
18
+ # Prediction function
19
  def predict(img):
20
+ img = PILImage.create(img)
21
  pred, idx, probs = learn.predict(img)
22
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
23
 
24
+ # Custom CSS
25
  custom_css = """
 
 
 
 
26
  button {
27
+ background-color: #00fbb9;
 
 
 
28
  color: #333;
29
+ border: none;
30
+ padding: 10px 20px;
31
+ border-radius: 5px;
32
  }
 
33
 
34
+ button:hover {
35
+ background-color: #00d6a7;
36
+ }
37
+ """
38
 
39
+ # Interface parameters
40
+ title = "Ethiopia TB Detection"
41
+ description = "Detect TB from chest x-rays"
42
  examples = ['patient1.png', 'patient2.png', 'patient3.png']
 
43
 
44
+ # Launch interface
45
+ gr.Interface(fn=predict,
46
+ inputs=gr.inputs.Image(shape=(512, 512)),
47
+ outputs=gr.outputs.Label(num_top_classes=1),
48
  title=title,
49
  description=description,
50
  examples=examples,
 
51
  css=custom_css).launch(inline=False)