import tensorflow as tf from fastapi import FastAPI from PIL import Image import numpy as np class BrainTumorDetector: def __init__(self, model_path): self.model = tf.keras.models.load_model(model_path) def predict(self, image: Image.Image): image = image.resize((224, 224)) # Adjust size as per your model image_array = np.array(image) / 255.0 # Normalize image_array = np.expand_dims(image_array, axis=0) # Add batch dimension predictions = self.model.predict(image_array) return predictions # Initialize the model detector (this path will be relative to your model repository) detector = BrainTumorDetector("Brain_tumor_pred.h5")