Slide 13
Slide 13 text
from fastapi import FastAPI, File, UploadFile
import tensorflow as tf
from PIL import Image
import numpy as np
app = FastAPI()
model = tf.keras.models.load_model('model/mango_model.h5')
@app.post("/predict/")
async def predict(file: UploadFile = File(...)):
image = Image.open(file.file)
img_array = np.array(image.resize((224, 224))) / 255.0
predictions = model.predict(np.expand_dims(img_array, 0))
return {"predictions": predictions.tolist()}