File size: 695 Bytes
f91d093
 
 
 
 
 
 
 
 
 
e8424a6
f91d093
 
 
 
 
 
fef9f79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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((128, 128))  # 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")