SANJAYV10 commited on
Commit
c4de414
1 Parent(s): a09bcf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -4,6 +4,11 @@ import keras
4
  import h5py
5
  import numpy as np
6
 
 
 
 
 
 
7
  app = FastAPI()
8
 
9
  # Load the model from the HDF5 file
@@ -11,24 +16,17 @@ model = keras.models.load_model("model_finetuned.h5")
11
 
12
  # Define a function to preprocess the image
13
  def preprocess_image(image):
14
- # Resize the image to a fixed size
15
- image = image.resize((224, 224))
16
- # Convert the image to a NumPy array
17
- image = np.array(image)
18
- # Normalize the image
19
- image = image / 255.0
20
- # Return the image
21
- return image
22
 
23
  # Define an endpoint to predict the output
24
- @app.post("/predict")
25
  async def predict_endpoint(image: fastapi.File):
26
  # Preprocess the image
27
  image = preprocess_image(image)
28
  # Make a prediction
29
  prediction = model.predict(image)
30
  # Return the prediction
31
- return {"prediction": prediction}
32
 
33
  if __name__ == "__main__":
34
  import uvicorn
 
4
  import h5py
5
  import numpy as np
6
 
7
+ from pydantic import BaseModel
8
+
9
+ class Prediction(BaseModel):
10
+ prediction: np.ndarray
11
+
12
  app = FastAPI()
13
 
14
  # Load the model from the HDF5 file
 
16
 
17
  # Define a function to preprocess the image
18
  def preprocess_image(image):
19
+ # ...
 
 
 
 
 
 
 
20
 
21
  # Define an endpoint to predict the output
22
+ @app.post("/predict", response_model=Prediction)
23
  async def predict_endpoint(image: fastapi.File):
24
  # Preprocess the image
25
  image = preprocess_image(image)
26
  # Make a prediction
27
  prediction = model.predict(image)
28
  # Return the prediction
29
+ return Prediction(prediction=prediction)
30
 
31
  if __name__ == "__main__":
32
  import uvicorn