SANJAYV10's picture
Update app.py
c4de414
raw
history blame
No virus
803 Bytes
from fastapi import FastAPI
import fastapi
import keras
import h5py
import numpy as np
from pydantic import BaseModel
class Prediction(BaseModel):
prediction: np.ndarray
app = FastAPI()
# Load the model from the HDF5 file
model = keras.models.load_model("model_finetuned.h5")
# Define a function to preprocess the image
def preprocess_image(image):
# ...
# Define an endpoint to predict the output
@app.post("/predict", response_model=Prediction)
async def predict_endpoint(image: fastapi.File):
# Preprocess the image
image = preprocess_image(image)
# Make a prediction
prediction = model.predict(image)
# Return the prediction
return Prediction(prediction=prediction)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)