Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import tensorflow as tf | |
| from tensorflow.keras.preprocessing import image | |
| from tensorflow.keras.applications.resnet50 import preprocess_input | |
| import numpy as np | |
| # Load the model | |
| model_path = 'fine_tuned_resnet50_brain_tumor.h5' | |
| model = tf.keras.models.load_model(model_path) | |
| def predict_image(img): | |
| img = img.resize((224, 224)) # Resize the image to match the model input size | |
| img_array = np.array(img) # Convert image to numpy array | |
| img_array = np.expand_dims(img_array, axis=0) # Add batch dimension | |
| img_array = preprocess_input(img_array) # Preprocess the image | |
| prediction = model.predict(img_array) # Predict | |
| predicted_class = np.round(prediction).astype(int)[0][0] | |
| return "Brain Tumor" if predicted_class == 0 else "Healthy" | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Text() | |
| ) | |
| # Launch the Gradio app and create a public link | |
| iface.launch(share=True) | |