File size: 753 Bytes
2a1e608 0804686 0c9a087 289f6c9 2a1e608 39cffd4 2a1e608 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastapi import FastAPI, File, UploadFile
import numpy as np
from PIL import Image
import io
import tensorflow as tf
model = tf.keras.models.load_model('946_.keras', compile=False)
app = FastAPI()
@app.post("/classify")
async def classify(image: UploadFile = File(...)):
if image is not None:
img = Image.open(io.BytesIO(await image.read()))
img = img.resize((64,64))
img_array = np.array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
predictions = model.predict(img_array)
predicted_class_idx = np.argmax(predictions)
predicted_class_idx = int(predicted_class_idx)
return {"prediction": predicted_class_idx}
else:
return {"error": "No image provided"} |