Spaces:
Sleeping
Sleeping
File size: 1,136 Bytes
c7e8622 c662a40 c7e8622 c662a40 1658bdc 44a0236 c7e8622 a70b7b1 abe5204 d34544a abe5204 6462de4 abe5204 c476e3f abe5204 6462de4 abe5204 35fa410 abe5204 f14de50 c662a40 671b81e c662a40 671b81e c7e8622 671b81e 1b96c12 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.keras.preprocessing import image
def predict_input_image(img):
# Normalize the image by cropping (center crop)
h, w = img.size
crop_start_x = (w - 224) // 2
crop_start_y = (h - 224) // 2
img = img.crop((crop_start_x, crop_start_y, crop_start_x + 224, crop_start_y + 224))
img = tf.image.resize(img, [224,224])
img = np.expand_dims(img, axis = 0)
my_model = load_model('Brain_Tumor_Model.h5')
# Set a threshold for binary classification
threshold = 0.5
# Make predictions using your model
predictions = my_model.predict(img)
# Convert predictions to binary (0 or 1) based on the threshold
binary_prediction = 'Tumor Detected' if predictions[0][0] > threshold else 'No Tumor Detected'
# Print or use the binary prediction as needed
print("Prediction:", binary_prediction)
# Define Gradio interface
iface = gr.Interface(
fn=predict_input_image,
inputs= 'image',
outputs="text",
)
# Launch the interface
iface.launch() |