ishanam commited on
Commit
1ecdff2
1 Parent(s): a7eb393

Add application file

Browse files
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import hf_hub_download
3
+ from fastai.learner import load_learner
4
+
5
+ from fastai.vision.all import *
6
+
7
+
8
+ class_list = ['BacterialPneumonia','COVID-19','Normal','ViralPneumonia']
9
+
10
+ def label_func(file):
11
+ print(f"file: {file}")
12
+ return "Normal" #file.parent.name
13
+
14
+ model = load_learner(
15
+ hf_hub_download("kmknair/xray-classification", "xray-classification-export.pkl")
16
+ )
17
+
18
+
19
+ def predict_image(file_path):
20
+ # img = PILImage.create(Path(file_path))
21
+ results = model.predict(file_path)
22
+ pred_class = class_list[results[1].item()]
23
+ pred_probs = f"{100*results[2][results[1].item()]:.2f}"
24
+ result_text = f"Predicted Results : {pred_class} probabilty: {pred_probs}"
25
+ print(result_text)
26
+ return result_text
27
+
28
+
29
+
30
+ xray_file_tab = gr.Interface(
31
+ fn=predict_image,
32
+ inputs=[
33
+ gr.Image(type="filepath", label="xray-classification")
34
+ ],
35
+ examples=[
36
+ ["samples/BacterialPneumonia/87.jpeg"],
37
+ ["samples/COVID-19/1.jpeg"],
38
+ ["samples/Normal/53.jpeg"],
39
+ ["samples/ViralPneumonia/106.jpeg"]
40
+ ],
41
+ description="upload or choose a sample image file",
42
+ outputs="text")
43
+
44
+ tabs = gr.TabbedInterface (
45
+ [
46
+ xray_file_tab
47
+ ],
48
+ [
49
+ "Xray Classification"
50
+ ]
51
+ )
52
+
53
+ if __name__ == "__main__":
54
+ tabs.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ torchaudio
4
+ transformers
5
+ fastai
samples/.DS_Store ADDED
Binary file (10.2 kB). View file
 
samples/BacterialPneumonia/311.jpeg ADDED
samples/BacterialPneumonia/87.jpeg ADDED
samples/COVID-19/1.jpeg ADDED
samples/COVID-19/7.jpeg ADDED
samples/Normal/53.jpeg ADDED
samples/Normal/70.jpeg ADDED
samples/ViralPneumonia/106.jpeg ADDED
samples/ViralPneumonia/134.jpeg ADDED