Anthony-Ml commited on
Commit
d03deea
·
unverified ·
2 Parent(s): 1c72a49 183ee03

Merge branch 'main' of hf.co:spaces/Anthony-Ml/covid_predictor

Browse files
Files changed (3) hide show
  1. Gradcam.png +0 -0
  2. app.py +52 -17
  3. requirements.txt +8 -1
Gradcam.png ADDED
app.py CHANGED
@@ -2,6 +2,56 @@ import gradio as gr
2
  from fastai.vision.all import *
3
  from efficientnet_pytorch import EfficientNet
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  #learn = load_learner('model/predictcovidfastaifinal18102023.pkl')
6
  learn = load_learner('model/final_20102023_eb7_model.pkl')
7
 
@@ -11,24 +61,9 @@ def predict_image(get_image):
11
  pred, idx, probs = learn.predict(get_image)
12
  return dict(zip(categories, map(float, probs)))
13
 
14
- title = "Detect COVID_19 Infection Xray Chest Images"
15
- description = """
16
- This Space demonstrates model based on efficientnet base model.
17
-
18
- The model is trained using [anasmohammedtahir/covidqu](https://www.kaggle.com/datasets/anasmohammedtahir/covidqu) dataset
19
- """
20
- examples = [
21
- ['covid/covid_1038.png'], ['covid/covid_1034.png'],
22
- ['covid/cd.png'], ['covid/covid_1021.png'],
23
- ['covid/covid_1027.png'], ['covid/covid_1042.png'],
24
- ['covid/covid_1031.png']]
25
-
26
- article="<p style='text-align: center'><a href='https://www.kaggle.com/datasets/anasmohammedtahir/covidqu' target='_blank'>COVID-QU-Ex Dataset</a></p>"
27
- interpretation="shap"
28
- num_shap=5
29
  enable_queue=True
30
 
31
-
32
  gr.Interface(fn=predict_image, inputs=gr.Image(shape=(224,224)),
33
- outputs = gr.Label(num_top_classes=3),title=title,description=description,examples=examples, article=article, interpretation=interpretation,enable_queue=enable_queue).launch(share=False)
34
 
 
2
  from fastai.vision.all import *
3
  from efficientnet_pytorch import EfficientNet
4
 
5
+ import torch, torchvision
6
+ from torchvision import transforms
7
+ from pytorch_grad_cam import GradCAM
8
+ from pytorch_grad_cam.utils.image import show_cam_on_image
9
+ from PIL import Image
10
+
11
+ title = "COVID_19 Infection Detectation App!"
12
+ head = (
13
+ "<body>"
14
+ "<center>"
15
+ "<img src='/file=Gradcam.png' width=200>"
16
+ "<h2>"
17
+ "This Space demonstrates a model based on efficientnetB7 base model. The Model was trained to classify chest xray image. To test it, "
18
+ "</h2>"
19
+ "<h3>"
20
+ "Use the Example Images provided below the up or Upload your own xray images with the App."
21
+ "</h3>"
22
+ "<h3>"
23
+ "!!!PLEASE NOTE MODEL WAS TRAINED and VALIDATED USING PNG FILES!!!"
24
+ "</h3>"
25
+ "</center>"
26
+ "<p>"
27
+ "<b>""<a href='https://www.kaggle.com/datasets/anasmohammedtahir/covidqu'>The model is trained using COVID-QU-Ex dataset</a>""</b>"
28
+ " that the researchers from Qatar University compiled,that consists of 33,920 chest X-ray (CXR) images including:"
29
+ "</p>"
30
+ "<ul>"
31
+ "<li>"
32
+ "11,956 COVID-19"
33
+ "</li>"
34
+ "<li>"
35
+ "11,263 Non-COVID infections (Viral or Bacterial Pneumonia)"
36
+ "</li>"
37
+ "<li>"
38
+ "10,701 Normal"
39
+ "</li>"
40
+ "</ul>"
41
+ "<p>"
42
+ "Thanks to Kaggle & KaggleX, this is the largest ever created lung mask dataset, that I am aware of publicly available as of October 2023."
43
+ "</p>"
44
+ "</body>"
45
+ )
46
+ description = head
47
+
48
+ examples = [
49
+ ['covid/covid_1038.png'], ['covid/covid_1034.png'],
50
+ ['covid/cd.png'], ['covid/covid_1021.png'],
51
+ ['covid/covid_1027.png'], ['covid/covid_1042.png'],
52
+ ['covid/covid_1031.png']
53
+ ]
54
+
55
  #learn = load_learner('model/predictcovidfastaifinal18102023.pkl')
56
  learn = load_learner('model/final_20102023_eb7_model.pkl')
57
 
 
61
  pred, idx, probs = learn.predict(get_image)
62
  return dict(zip(categories, map(float, probs)))
63
 
64
+ interpretation= 'shap'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  enable_queue=True
66
 
 
67
  gr.Interface(fn=predict_image, inputs=gr.Image(shape=(224,224)),
68
+ outputs = gr.Label(num_top_classes=3),title=title,description=description,examples=examples, interpretation=interpretation,enable_queue=enable_queue).launch(share=False)
69
 
requirements.txt CHANGED
@@ -1,2 +1,9 @@
1
  fastai
2
- efficientnet-pytorch
 
 
 
 
 
 
 
 
1
  fastai
2
+ efficientnet-pytorch
3
+ torch
4
+ torchvision
5
+ torch-lr-finder
6
+ pytorch-lightning
7
+ grad-cam
8
+ pillow
9
+ numpy