Spaces:
Sleeping
Sleeping
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('_9217') | |
app = FastAPI() | |
async def classify(image: UploadFile = File(...)): | |
if image is not None: | |
img = Image.open(io.BytesIO(await image.read())) | |
img = img.resize((128, 128)) | |
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"} | |