DHEIVER prafullcodes commited on
Commit
2f3eced
·
0 Parent(s):

Duplicate from prafullcodes/PrafullInterfaces

Browse files

Co-authored-by: Prafull Mangla <prafullcodes@users.noreply.huggingface.co>

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +228 -0
  4. lung_image_sets/lung_aca/lungaca1.jpeg +0 -0
  5. lung_image_sets/lung_aca/lungaca10.jpeg +0 -0
  6. lung_image_sets/lung_aca/lungaca100.jpeg +0 -0
  7. lung_image_sets/lung_aca/lungaca1000.jpeg +0 -0
  8. lung_image_sets/lung_aca/lungaca1001.jpeg +0 -0
  9. lung_image_sets/lung_aca/lungaca1002.jpeg +0 -0
  10. lung_image_sets/lung_aca/lungaca1003.jpeg +0 -0
  11. lung_image_sets/lung_aca/lungaca1004.jpeg +0 -0
  12. lung_image_sets/lung_aca/lungaca1005.jpeg +0 -0
  13. lung_image_sets/lung_aca/lungaca1006.jpeg +0 -0
  14. lung_image_sets/lung_aca/lungaca1007.jpeg +0 -0
  15. lung_image_sets/lung_aca/lungaca1008.jpeg +0 -0
  16. lung_image_sets/lung_aca/lungaca1009.jpeg +0 -0
  17. lung_image_sets/lung_aca/lungaca101.jpeg +0 -0
  18. lung_image_sets/lung_aca/lungaca1010.jpeg +0 -0
  19. lung_image_sets/lung_aca/lungaca1011.jpeg +0 -0
  20. lung_image_sets/lung_aca/lungaca1012.jpeg +0 -0
  21. lung_image_sets/lung_aca/lungaca1013.jpeg +0 -0
  22. lung_image_sets/lung_aca/lungaca1014.jpeg +0 -0
  23. lung_image_sets/lung_aca/lungaca1015.jpeg +0 -0
  24. lung_image_sets/lung_aca/lungaca1016.jpeg +0 -0
  25. lung_image_sets/lung_aca/lungaca1017.jpeg +0 -0
  26. lung_image_sets/lung_aca/lungaca1018.jpeg +0 -0
  27. lung_image_sets/lung_aca/lungaca1019.jpeg +0 -0
  28. lung_image_sets/lung_aca/lungaca102.jpeg +0 -0
  29. lung_image_sets/lung_aca/lungaca1020.jpeg +0 -0
  30. lung_image_sets/lung_aca/lungaca1021.jpeg +0 -0
  31. lung_image_sets/lung_aca/lungaca1022.jpeg +0 -0
  32. lung_image_sets/lung_aca/lungaca1023.jpeg +0 -0
  33. lung_image_sets/lung_aca/lungaca1024.jpeg +0 -0
  34. lung_image_sets/lung_aca/lungaca1025.jpeg +0 -0
  35. lung_image_sets/lung_aca/lungaca1026.jpeg +0 -0
  36. lung_image_sets/lung_aca/lungaca1027.jpeg +0 -0
  37. lung_image_sets/lung_aca/lungaca1028.jpeg +0 -0
  38. lung_image_sets/lung_aca/lungaca1029.jpeg +0 -0
  39. lung_image_sets/lung_aca/lungaca103.jpeg +0 -0
  40. lung_image_sets/lung_aca/lungaca1030.jpeg +0 -0
  41. lung_image_sets/lung_aca/lungaca1031.jpeg +0 -0
  42. lung_image_sets/lung_aca/lungaca1032.jpeg +0 -0
  43. lung_image_sets/lung_aca/lungaca1033.jpeg +0 -0
  44. lung_image_sets/lung_aca/lungaca1034.jpeg +0 -0
  45. lung_image_sets/lung_aca/lungaca1035.jpeg +0 -0
  46. lung_image_sets/lung_aca/lungaca1036.jpeg +0 -0
  47. lung_image_sets/lung_aca/lungaca1037.jpeg +0 -0
  48. lung_image_sets/lung_aca/lungaca1038.jpeg +0 -0
  49. lung_image_sets/lung_aca/lungaca1039.jpeg +0 -0
  50. lung_image_sets/lung_aca/lungaca104.jpeg +0 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: PrafullInterfaces
3
+ emoji: 📉
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.28.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: openrail
11
+ duplicated_from: prafullcodes/PrafullInterfaces
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """lung cancerdetection.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1f7VybSnYLPbUVLRLMNQboxQkCYaBCXMs
8
+ """
9
+
10
+
11
+ # This Python 3 environment comes with many helpful analytics libraries installed
12
+ # It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
13
+ # For example, here's several helpful packages to load
14
+
15
+ import numpy as np # linear algebra
16
+ import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
17
+
18
+ # Input data files are available in the read-only "../input/" directory
19
+ # For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
20
+
21
+ import os
22
+
23
+
24
+ # You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
25
+ # You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
26
+
27
+ # importing libraries
28
+
29
+ import tensorflow as tf
30
+ from tensorflow.keras.layers import Input, Lambda, Dense, Flatten
31
+ from tensorflow.keras.models import Model
32
+ from tensorflow.keras.applications.resnet50 import ResNet50
33
+ from tensorflow.keras.applications.resnet50 import preprocess_input
34
+ from tensorflow.keras.preprocessing import image
35
+ from tensorflow.keras.preprocessing.image import ImageDataGenerator,load_img
36
+ from tensorflow.keras.models import Sequential
37
+ import numpy as np
38
+ from glob import glob
39
+ import matplotlib.pyplot as plt
40
+
41
+ image_set = "./lung_image_sets"
42
+
43
+ SIZE_X = SIZE_Y = 224
44
+
45
+ datagen = tf.keras.preprocessing.image.ImageDataGenerator(validation_split = 0.2)
46
+
47
+ train_set = datagen.flow_from_directory(image_set,
48
+ class_mode = "categorical",
49
+ target_size = (SIZE_X,SIZE_Y),
50
+ color_mode="rgb",
51
+ batch_size = 128,
52
+ shuffle = False,
53
+ subset='training',
54
+ seed = 42)
55
+
56
+ validate_set = datagen.flow_from_directory(image_set,
57
+ class_mode = "categorical",
58
+ target_size = (SIZE_X, SIZE_Y),
59
+ color_mode="rgb",
60
+ batch_size = 128,
61
+ shuffle = False,
62
+ subset='validation',
63
+ seed = 42)
64
+
65
+
66
+ IMAGE_SIZE = [224, 224]
67
+
68
+ resnet = ResNet50(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)
69
+
70
+ # don't train existing weights
71
+ for layer in resnet.layers:
72
+ layer.trainable = False
73
+
74
+ flatten = Flatten()(resnet.output)
75
+ dense = Dense(256, activation = 'relu')(flatten)
76
+ dense = Dense(128, activation = 'relu')(dense)
77
+ prediction = Dense(3, activation = 'softmax')(dense)
78
+
79
+ #creating a model
80
+ model = Model(inputs = resnet.input, outputs = prediction )
81
+
82
+ model.summary()
83
+
84
+ model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
85
+
86
+ #executing the model
87
+ history = model.fit(train_set, validation_data = (validate_set), epochs = 8, verbose = 1)
88
+
89
+ # plotting the loss
90
+ plt.plot(history.history['loss'],label = 'train_loss')
91
+ plt.plot(history.history['val_loss'], label = 'testing_loss')
92
+ plt.title('loss')
93
+ plt.legend()
94
+ plt.show()
95
+
96
+ # Both Validation and Training accuracy is shown here
97
+
98
+ plt.plot(history.history['accuracy'], label='training_accuracy')
99
+ plt.plot(history.history['val_accuracy'], label='validation accuracy')
100
+ plt.title('Accuracy')
101
+ plt.legend()
102
+ plt.show()
103
+
104
+ # CHECKING THE CONFUSION MATRIX
105
+
106
+ from sklearn.metrics import classification_report
107
+ from sklearn.metrics import confusion_matrix
108
+ from sklearn.metrics import f1_score
109
+ Y_pred = model.predict(validate_set)
110
+ y_pred = np.argmax(Y_pred ,axis =1)
111
+ print('Confusion Matrix')
112
+ confusion_matrix = confusion_matrix(validate_set.classes, y_pred)
113
+ print(confusion_matrix)
114
+ print('Classification Report')
115
+ target_names = ['aca','n', 'scc']
116
+ print(classification_report(validate_set.classes, y_pred, target_names=target_names))
117
+
118
+ result = model.evaluate(validate_set,batch_size=128)
119
+ print("test_loss, test accuracy",result)
120
+
121
+ import pickle
122
+
123
+ with open('model_pkl', 'wb') as files:
124
+ pickle.dump(model, files)
125
+
126
+ # img = tf.keras.utils.load_img('/content/lung_colon_image_set/lung_image_sets/lung_aca/lungaca1.jpeg', target_size=(224, 224))
127
+ # img_array = tf.keras.utils.img_to_array(img)
128
+ # img_array = tf.expand_dims(img_array, 0)
129
+
130
+ # # load saved model
131
+ # with open('model_pkl' , 'rb') as f:
132
+ # lr = pickle.load(f)
133
+ # predi=lr.predict(img_array)
134
+ # print(predi)
135
+ # image_output_class=target_names[np.argmax(predi)]
136
+
137
+ # print("The predicted class is", image_output_class)
138
+
139
+ import gradio as gd
140
+ from PIL import Image
141
+
142
+ css_class="""
143
+ body{ background-color:rgb(10, 30, 75)}
144
+ ul>li{
145
+ text-decoration: none;
146
+ list-style:none;
147
+ margin: 1px;
148
+ padding:.5px
149
+ }
150
+ h3{
151
+ color: rgb(24, 46, 98);
152
+ margin: 1px;
153
+ padding:.5px
154
+ text-align: center;
155
+ }
156
+ h4{
157
+ text-decoration: underline;
158
+ color: rgb(218, 57, 57);
159
+ text-align: center;
160
+ }
161
+
162
+ """
163
+ def acaClassOutput():
164
+ return '''
165
+ <h3>You CT Scan Report:-</h3>
166
+ <hr>
167
+ <h4>You have Adenocarcinoma type cancer</h4>
168
+ <p>It is Non-small cell type cancer which has effected you 40% of lung cells.</p>
169
+ <ul>
170
+ <h4>You can try These cautions</h4>
171
+ <li>Try Radiation therapy, Chemotherapy, Targeted therapy, Immunotherapy</li>
172
+ <li>Try to stay away from Smokers and air pollution</li>
173
+ <li>Concern with your doctor for more details.</li>
174
+ </ul>
175
+ '''
176
+
177
+ def sccClassOutput():
178
+ return '''
179
+ <h3>You CT Scan Report:-</h3>
180
+ <hr>
181
+ <h4>You have Squamous type cancer</h4>
182
+ <p>It effects the broncial tube of lungs. You probably have smoke history as it effected your 30% lungs</p>
183
+ <ul>
184
+ <h4>You can try These cautions</h4>
185
+ <li>Try Radiation therapy, Chemotherapy, Targeted therapy, Immunotherapy</li>
186
+ <li>Try to stay away from Smokers and air pollution</li>
187
+ <li>Concern with your doctor for more details.</li>
188
+ '''
189
+
190
+ def nClassOutput():
191
+ return '''
192
+ <h3>You CT Scan Report:-</h3>
193
+ <hr>
194
+ <h4>You have Neuroendocrine type cancer</h4>
195
+ <p>This type of cancer effect neuroendocrine which are responsible for producing harmones. This is less common than other types</p>
196
+ <ul>
197
+ <h4>You can try These cautions</h4>
198
+ <li>Try regular screening if you have smoke history. Try surgeries</li>
199
+ <li>Try to stay away from Smokers and air pollution</li>
200
+ <li>Concern with your doctor for more details.</li>
201
+ '''
202
+ # target_names = ['aca','n', 'scc']
203
+ def predictOutPut(image_class):
204
+ output=''
205
+ if(image_class=='aca'):
206
+ output=acaClassOutput()
207
+ elif(image_class=='n'):
208
+ output=nClassOutput()
209
+ elif(image_class=='scc'):
210
+ output=sccClassOutput()
211
+ return output
212
+
213
+ def greet_user(CTScanImage):
214
+ image=gd.inputs.Image()
215
+ pil_image = Image.fromarray(CTScanImage.astype('uint8'), 'RGB')
216
+ pil_image_resized = pil_image.resize((224,224))
217
+ img_array = tf.keras.utils.img_to_array(pil_image_resized)
218
+ img_array = tf.expand_dims(img_array, 0)
219
+ with open('model_pkl' , 'rb') as f:
220
+ lr = pickle.load(f)
221
+ predi=lr.predict(img_array)
222
+ image_output_class=target_names[np.argmax(predi)]
223
+ return predictOutPut(image_output_class)
224
+
225
+ customInput=gd.inputs.Image(label="Upload You CT Scanned Image")
226
+ customOutput=gd.outputs.HTML(label="Your CT scan Report")
227
+ app = gd.Interface(fn = greet_user, inputs=customInput, outputs=customOutput,title="Lung Cancer Detection", description="Upload your CT Scan Image to know Whether You have cancer or not",css=css_class)
228
+ app.launch()
lung_image_sets/lung_aca/lungaca1.jpeg ADDED
lung_image_sets/lung_aca/lungaca10.jpeg ADDED
lung_image_sets/lung_aca/lungaca100.jpeg ADDED
lung_image_sets/lung_aca/lungaca1000.jpeg ADDED
lung_image_sets/lung_aca/lungaca1001.jpeg ADDED
lung_image_sets/lung_aca/lungaca1002.jpeg ADDED
lung_image_sets/lung_aca/lungaca1003.jpeg ADDED
lung_image_sets/lung_aca/lungaca1004.jpeg ADDED
lung_image_sets/lung_aca/lungaca1005.jpeg ADDED
lung_image_sets/lung_aca/lungaca1006.jpeg ADDED
lung_image_sets/lung_aca/lungaca1007.jpeg ADDED
lung_image_sets/lung_aca/lungaca1008.jpeg ADDED
lung_image_sets/lung_aca/lungaca1009.jpeg ADDED
lung_image_sets/lung_aca/lungaca101.jpeg ADDED
lung_image_sets/lung_aca/lungaca1010.jpeg ADDED
lung_image_sets/lung_aca/lungaca1011.jpeg ADDED
lung_image_sets/lung_aca/lungaca1012.jpeg ADDED
lung_image_sets/lung_aca/lungaca1013.jpeg ADDED
lung_image_sets/lung_aca/lungaca1014.jpeg ADDED
lung_image_sets/lung_aca/lungaca1015.jpeg ADDED
lung_image_sets/lung_aca/lungaca1016.jpeg ADDED
lung_image_sets/lung_aca/lungaca1017.jpeg ADDED
lung_image_sets/lung_aca/lungaca1018.jpeg ADDED
lung_image_sets/lung_aca/lungaca1019.jpeg ADDED
lung_image_sets/lung_aca/lungaca102.jpeg ADDED
lung_image_sets/lung_aca/lungaca1020.jpeg ADDED
lung_image_sets/lung_aca/lungaca1021.jpeg ADDED
lung_image_sets/lung_aca/lungaca1022.jpeg ADDED
lung_image_sets/lung_aca/lungaca1023.jpeg ADDED
lung_image_sets/lung_aca/lungaca1024.jpeg ADDED
lung_image_sets/lung_aca/lungaca1025.jpeg ADDED
lung_image_sets/lung_aca/lungaca1026.jpeg ADDED
lung_image_sets/lung_aca/lungaca1027.jpeg ADDED
lung_image_sets/lung_aca/lungaca1028.jpeg ADDED
lung_image_sets/lung_aca/lungaca1029.jpeg ADDED
lung_image_sets/lung_aca/lungaca103.jpeg ADDED
lung_image_sets/lung_aca/lungaca1030.jpeg ADDED
lung_image_sets/lung_aca/lungaca1031.jpeg ADDED
lung_image_sets/lung_aca/lungaca1032.jpeg ADDED
lung_image_sets/lung_aca/lungaca1033.jpeg ADDED
lung_image_sets/lung_aca/lungaca1034.jpeg ADDED
lung_image_sets/lung_aca/lungaca1035.jpeg ADDED
lung_image_sets/lung_aca/lungaca1036.jpeg ADDED
lung_image_sets/lung_aca/lungaca1037.jpeg ADDED
lung_image_sets/lung_aca/lungaca1038.jpeg ADDED
lung_image_sets/lung_aca/lungaca1039.jpeg ADDED
lung_image_sets/lung_aca/lungaca104.jpeg ADDED