File size: 803 Bytes
a09bcf9
6d489a6
530f1fe
a09bcf9
 
c2551f6
c4de414
 
 
 
 
c2551f6
c5f6a7a
530f1fe
f7cdcd7
c5f6a7a
32a363f
 
c4de414
c5f6a7a
 
c4de414
c5f6a7a
 
 
 
 
 
c4de414
c5f6a7a
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)