Update app.py
Browse files
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, (
|
14 |
-
img = img.reshape(1,
|
15 |
|
16 |
-
# Predict using the model
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
#
|
22 |
-
if
|
23 |
-
result =
|
24 |
-
elif p == 1:
|
25 |
-
result = 'Meningioma Tumor'
|
26 |
-
elif p == 2:
|
27 |
-
result = 'No Tumor'
|
28 |
else:
|
29 |
-
result =
|
30 |
|
31 |
-
|
|
|
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(
|