Addai commited on
Commit
a6d2687
·
verified ·
1 Parent(s): a340799

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -11
app.py CHANGED
@@ -1,21 +1,43 @@
1
  import gradio as gr
2
- from fastai.vision.all import load_learner, PILImage
 
3
 
 
4
  learn = load_learner('export.pkl')
 
 
5
  labels = learn.dls.vocab
6
 
 
7
  def predict(img):
8
  img = PILImage.create(img)
9
  pred, pred_idx, probs = learn.predict(img)
10
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
11
 
12
- iface = gr.Interface(
13
- fn=predict,
14
- inputs=gr.Image(),
15
- outputs=gr.Label(num_top_classes=3),
16
- title="Breast Cancer Detection",
17
- description="Upload a breast X-ray image to detect potential issues.",
18
- examples=['img1.jpeg', 'img2.jpeg']
19
- )
 
 
 
 
 
 
20
 
21
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
 
5
+ # Load the model
6
  learn = load_learner('export.pkl')
7
+
8
+ # Get labels
9
  labels = learn.dls.vocab
10
 
11
+ # Prediction function
12
  def predict(img):
13
  img = PILImage.create(img)
14
  pred, pred_idx, probs = learn.predict(img)
15
+ prediction = str(pred)
16
+ return prediction
17
 
18
+ # App configuration
19
+ title = "Breast cancer detection with Deep Transfer Learning(ResNet18)."
20
+ description = """
21
+ <p style='text-align: center'>
22
+ <b>As a radiologist or oncologist, it is crucial to know what is wrong with a breast x-ray image.</b><br>
23
+ <b>Upload the breast X-ray image to know what is wrong with a patient's breast with or without implant.</b><br>
24
+ This product is from the findings of my (Team) published research paper:
25
+ <a href='https://iopscience.iop.org/article/10.1088/2057-1976/ad3cdf' target='_blank' style='color: blue;'>read paper</a>.<br>
26
+ Learn more about me: <a href='https://www.linkedin.com/in/fosberg-addai-53a6991a7/' target='_blank' style='color: blue;'>Fosberg Addai</a>
27
+ </p>
28
+ """
29
+ article = "<p style='text-align: center'>Web app is built and managed by Addai Fosberg</p>"
30
+ examples = ['img1.jpeg', 'img2.jpeg']
31
+ enable_queue = True
32
 
33
+ # Update the interface components
34
+ gr.Interface(
35
+ fn=predict,
36
+ inputs=gr.Image(shape=(512, 512)), # Updated input component
37
+ outputs=gr.Label(num_top_classes=3), # Updated output component
38
+ title=title,
39
+ description=description,
40
+ article=article,
41
+ examples=examples,
42
+ enable_queue=enable_queue
43
+ ).launch()