prshanthreddy commited on
Commit
fcef679
·
verified ·
1 Parent(s): 2017254

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -13,48 +13,47 @@ X = Y = 224
13
  import os
14
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
15
 
16
- def preprocess_image(uploaded_image, predicted_label):
17
- # Read image bytes from uploaded file
18
- file_bytes = np.asarray(bytearray(uploaded_image.read()), dtype=np.uint8)
19
- img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
20
-
21
- if img is None:
22
- raise ValueError("Failed to load the uploaded image.")
23
-
24
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
25
  img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
26
  thresh = threshold_otsu(img_gray)
27
  img_otsu = img_gray < thresh
28
  total_area = img_otsu.size
29
  black_area = np.count_nonzero(img_otsu == 0)
30
  white_area = np.count_nonzero(img_otsu == 1)
31
-
 
 
32
  if predicted_label != 'lung_n':
33
  if white_area >= 300000:
34
  level = 3
35
  elif 200000 <= white_area < 3000000:
36
  level = 2
37
- elif 100000 <= white_area < 200000:
38
  level = 1
39
  elif white_area < 100000:
40
  level = 0
41
 
42
  if level == 3:
43
- st.error("Cancer type: " + predicted_label)
44
  st.error("Level of Cancer: 3")
45
- elif level == 2:
46
- st.warning("Cancer type: " + predicted_label)
 
47
  st.warning("Level of Cancer: 2")
 
48
  elif level == 1:
49
- st.info("Cancer type: " + predicted_label)
50
  st.info("Level of Cancer: 1")
51
  elif level == 0:
52
- st.success("Cancer type: " + predicted_label)
53
  st.success("Level of Cancer: 0")
54
  else:
55
  st.success("Predicted as Lung with Benign Tumor")
56
 
57
 
 
58
  # Create a Streamlit application
59
  def main():
60
  st.title('Lung Cancer Detection & Severity Level using Deep Learning')
 
13
  import os
14
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
15
 
16
+ def preprocess_image(image, predicted_label):
17
+ img= cv2.imread(image.name)
18
+ img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
 
 
 
 
 
 
19
  img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
20
  thresh = threshold_otsu(img_gray)
21
  img_otsu = img_gray < thresh
22
  total_area = img_otsu.size
23
  black_area = np.count_nonzero(img_otsu == 0)
24
  white_area = np.count_nonzero(img_otsu == 1)
25
+ #print(total_area)
26
+ #print(white_area)
27
+ #print(black_area)
28
  if predicted_label != 'lung_n':
29
  if white_area >= 300000:
30
  level = 3
31
  elif 200000 <= white_area < 3000000:
32
  level = 2
33
+ elif 100000 <= white_area < 200000:
34
  level = 1
35
  elif white_area < 100000:
36
  level = 0
37
 
38
  if level == 3:
39
+ st.error("Cancer type: "+ predicted_label )
40
  st.error("Level of Cancer: 3")
41
+ #st.error("Please consult a doctor immediately")
42
+ elif level == 2:
43
+ st.warning("Cancer type: "+ predicted_label )
44
  st.warning("Level of Cancer: 2")
45
+
46
  elif level == 1:
47
+ st.info("Cancer type: "+ predicted_label)
48
  st.info("Level of Cancer: 1")
49
  elif level == 0:
50
+ st.success("Cancer type: "+ predicted_label)
51
  st.success("Level of Cancer: 0")
52
  else:
53
  st.success("Predicted as Lung with Benign Tumor")
54
 
55
 
56
+
57
  # Create a Streamlit application
58
  def main():
59
  st.title('Lung Cancer Detection & Severity Level using Deep Learning')