LovnishVerma commited on
Commit
7f9fd20
1 Parent(s): 5f57a29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -11
app.py CHANGED
@@ -12,17 +12,6 @@ braintumor_model = load_model('models/brain_tumor_binary.h5')
12
  # Configuring Streamlit
13
  st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
14
 
15
- # Configuring Gradio
16
- iface = gr.Interface(
17
- fn="predict_braintumor",
18
- inputs="image",
19
- outputs="text",
20
- live=True,
21
- interpretation="default",
22
- examples=[["examples/1_no.jpeg"], ["examples/2_no.jpeg"], ["examples/3_no.jpg"], ["examples/Y1.jpg"], ["examples/Y2.jpg"], ["examples/Y3.jpg"]]
23
- )
24
- iface.launch()
25
-
26
  def preprocess_image(img):
27
  # If it's a NumPy array, use it directly
28
  if isinstance(img, np.ndarray):
@@ -56,3 +45,39 @@ def predict_braintumor(img):
56
  # Handle binary decision
57
  confidence = pred[0][0]
58
  return "Brain Tumor Not Found!" if binary_decision(confidence) == 1 else "Brain Tumor Found!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Configuring Streamlit
13
  st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
14
 
 
 
 
 
 
 
 
 
 
 
 
15
  def preprocess_image(img):
16
  # If it's a NumPy array, use it directly
17
  if isinstance(img, np.ndarray):
 
45
  # Handle binary decision
46
  confidence = pred[0][0]
47
  return "Brain Tumor Not Found!" if binary_decision(confidence) == 1 else "Brain Tumor Found!"
48
+
49
+ def preprocess_imgs(set_name, img_size):
50
+ set_new = []
51
+ for img in set_name:
52
+ img = cv2.resize(img, dsize=img_size, interpolation=cv2.INTER_CUBIC)
53
+ set_new.append(preprocess_input(img))
54
+ return np.array(set_new)
55
+
56
+ def crop_imgs(set_name, add_pixels_value=0):
57
+ set_new = []
58
+ for img in set_name:
59
+ gray = cv2.GaussianBlur(img, (5, 5), 0)
60
+ thresh = cv2.threshold(gray, 45, 255, cv2.THRESH_BINARY)[1]
61
+ thresh = cv2.erode(thresh, None, iterations=2)
62
+ thresh = cv2.dilate(thresh, None, iterations=2)
63
+ cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
64
+ cnts = cnts[0] if len(cnts) == 2 else cnts[1]
65
+ c = max(cnts, key=cv2.contourArea)
66
+ extLeft = tuple(c[c[:, :, 0].argmin()][0])
67
+ extRight = tuple(c[c[:, :, 0].argmax()][0])
68
+ extTop = tuple(c[c[:, :, 1].argmin()][0])
69
+ extBot = tuple(c[c[:, :, 1].argmax()][0])
70
+ ADD_PIXELS = add_pixels_value
71
+ new_img = img[extTop[1] - ADD_PIXELS:extBot[1] + ADD_PIXELS,
72
+ extLeft[0] - ADD_PIXELS:extRight[0] + ADD_PIXELS].copy()
73
+ set_new.append(new_img)
74
+ return np.array(set_new)
75
+
76
+ # Gradio interface
77
+ iface = gr.Interface(
78
+ fn=predict_braintumor,
79
+ inputs="image",
80
+ outputs="text",
81
+ examples=[["examples/1_no.jpeg"], ["examples/2_no.jpeg"], ["examples/3_no.jpg"], ["examples/Y1.jpg"], ["examples/Y2.jpg"], ["examples/Y3.jpg"]]
82
+ )
83
+ iface.launch()