mfkhaneducationtwo commited on
Commit
3c83744
·
verified ·
1 Parent(s): 131aad6

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -35
main.py DELETED
@@ -1,35 +0,0 @@
1
- from fastapi import FastAPI, UploadFile, File
2
- import numpy as np
3
- from PIL import Image
4
- import io
5
- from tensorflow import keras
6
-
7
- # Load the model
8
- model = keras.models.load_model("model.h5")
9
-
10
- # Hardcoded class labels (ensure this matches your training order)
11
- class_labels = ['NORMAL', 'PNEUMONIA']
12
-
13
- # Initialize FastAPI app
14
- app = FastAPI()
15
-
16
- # Preprocessing function
17
- def preprocess_image(image_bytes):
18
- image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
19
- image = image.resize((224, 224)) # match model input size
20
- img_array = np.array(image) / 255.0 # normalize
21
- img_array = np.expand_dims(img_array, axis=0) # add batch dimension
22
- return img_array
23
-
24
- # Prediction endpoint
25
- @app.post("/predict")
26
- async def predict(file: UploadFile = File(...)):
27
- image_bytes = await file.read()
28
- img_array = preprocess_image(image_bytes)
29
- predictions = model.predict(img_array)
30
- predicted_class = class_labels[np.argmax(predictions)]
31
- confidence = float(np.max(predictions))
32
- return {
33
- "prediction": predicted_class,
34
- "confidence": confidence
35
- }