LovnishVerma commited on
Commit
e769983
1 Parent(s): f1bea19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -55,17 +55,22 @@ def binary_decision(confidence):
55
  return 1 if confidence >= 0.5 else 0
56
 
57
  def predict_braintumor(img):
58
- # Save the uploaded file
59
- filename = "temp_image.png"
60
- file_path = os.path.join(UPLOAD_FOLDER, filename)
 
61
 
62
- # Convert Gradio image data to bytes
63
- img_bytes = img.read()
64
-
65
- with open(file_path, "wb") as f:
66
- f.write(img_bytes)
67
 
68
- img_gray = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
 
 
 
 
 
 
 
69
 
70
  # Crop and preprocess the grayscale image
71
  img_processed = crop_imgs([img_gray])
@@ -78,6 +83,7 @@ def predict_braintumor(img):
78
  confidence = pred[0][0]
79
  return "Brain Tumor Found!" if binary_decision(confidence) == 1 else "Brain Tumor Not Found!"
80
 
 
81
  def main():
82
  st.title("Brain Tumor Prediction App")
83
 
 
55
  return 1 if confidence >= 0.5 else 0
56
 
57
  def predict_braintumor(img):
58
+ # Save the uploaded file if it's a file-like object
59
+ if hasattr(img, 'read'):
60
+ filename = "temp_image.png"
61
+ file_path = os.path.join(UPLOAD_FOLDER, filename)
62
 
63
+ # Convert Gradio image data to bytes
64
+ img_bytes = img.read()
 
 
 
65
 
66
+ with open(file_path, "wb") as f:
67
+ f.write(img_bytes)
68
+
69
+ img_gray = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
70
+
71
+ # If it's a NumPy array, use it directly
72
+ elif isinstance(img, np.ndarray):
73
+ img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
74
 
75
  # Crop and preprocess the grayscale image
76
  img_processed = crop_imgs([img_gray])
 
83
  confidence = pred[0][0]
84
  return "Brain Tumor Found!" if binary_decision(confidence) == 1 else "Brain Tumor Not Found!"
85
 
86
+
87
  def main():
88
  st.title("Brain Tumor Prediction App")
89