CoolFace
Apppublic

MayoorMoolya/ML_Project

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py44 linesDownload Raw Back to root
1from PIL import Image2import numpy as np3import gradio as gr4import tensorflow as tf5from tensorflow.keras.preprocessing.image import load_img, img_to_array6import matplotlib.pyplot as plt7 8model = tf.keras.models.load_model('bestmodel (1).h5')9 10def predict_image(image):11    # Open image using PIL12    image = Image.fromarray(np.uint8(image))13 14    # Resize image using PIL15    image = image.resize((224, 224))16 17    # Convert image to numpy array18    input_arr = np.array(image) / 25519 20    # Expand the shape of the array to match the input shape of the model21    input_arr = np.expand_dims(input_arr, axis=0)22 23    # Make prediction using the model24    pred = model.predict(input_arr)[0][0]25 26    # Return prediction result27    if pred == 1:28      return "The MRI is a healthy one"29        30    else:31      return "The MRI has a tumor"32 33 34# Create a Gradio interface for the predict_image function35gr_interface = gr.Interface(36    predict_image,37    inputs="image",38    outputs="text",39    title="Brain Tumor Detector",40    description="Upload an MRI scan of the brain to determine whether or not it contains a tumor.",41    )42 43# Show the interface44gr_interface.launch()