pavankm96 commited on
Commit
52a79b1
·
verified ·
1 Parent(s): 35f7c4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -10,25 +10,22 @@ model = tf.keras.models.load_model("Brain Tumors.h5")
10
  def img_pred(upload):
11
  # Convert the Gradio input image to OpenCV format
12
  opencvImage = cv2.cvtColor(np.array(upload), cv2.COLOR_RGB2BGR)
13
- img = cv2.resize(opencvImage, (224, 224))
14
- img = img.reshape(1, 224, 224, 3)
15
 
16
- # Predict using the model
17
- p = model.predict(img)
18
- confidence = np.max(p)
19
- p = np.argmax(p, axis=1)[0]
20
 
21
- # Map prediction to tumor type
22
- if p == 0:
23
- result = 'Glioma Tumor'
24
- elif p == 1:
25
- result = 'Meningioma Tumor'
26
- elif p == 2:
27
- result = 'No Tumor'
28
  else:
29
- result = 'Pituitary Tumor'
30
 
31
- return f'The Model predicts: {result} with confidence {confidence}'
 
32
 
33
  # Define Gradio interface
34
  iface = gr.Interface(
 
10
  def img_pred(upload):
11
  # Convert the Gradio input image to OpenCV format
12
  opencvImage = cv2.cvtColor(np.array(upload), cv2.COLOR_RGB2BGR)
13
+ img = cv2.resize(opencvImage, (150, 150))
14
+ img = img.reshape(1, 150, 150, 3)
15
 
16
+ # Predict using the model and get confidence
17
+ predictions = model.predict(img)[0] # Get probabilities for each class
18
+ predicted_class = np.argmax(predictions) # Index of the predicted class
19
+ confidence = predictions[predicted_class] # Confidence of the predicted class
20
 
21
+ # Determine if tumor is present
22
+ if predicted_class == 0:
23
+ result = "No Tumor"
 
 
 
 
24
  else:
25
+ result = "Tumor Detected"
26
 
27
+ # Return result with confidence
28
+ return f"The Model predicts: {result} with a confidence of {confidence:.2%}"
29
 
30
  # Define Gradio interface
31
  iface = gr.Interface(