pavankm96 commited on
Commit
f91d093
1 Parent(s): d054534

Create model.py

Browse files
Files changed (1) hide show
  1. model.py +18 -0
model.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from fastapi import FastAPI
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ class BrainTumorDetector:
7
+ def __init__(self, model_path):
8
+ self.model = tf.keras.models.load_model(model_path)
9
+
10
+ def predict(self, image: Image.Image):
11
+ image = image.resize((224, 224)) # Adjust size as per your model
12
+ image_array = np.array(image) / 255.0 # Normalize
13
+ image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
14
+ predictions = self.model.predict(image_array)
15
+ return predictions
16
+
17
+ # Initialize the model detector (this path will be relative to your model repository)
18
+ detector = BrainTumorDetector("path/to/your/model.h5")