Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, File, UploadFile | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| import io | |
| app = FastAPI() | |
| # Load model | |
| model = tf.keras.models.load_model("saved_model") | |
| def preprocess(image): | |
| image = image.resize((224, 224)) | |
| image = np.array(image) / 255.0 | |
| return np.expand_dims(image, axis=0) | |
| def root(): | |
| return {"message": "Model is running!"} | |
| async def predict(file: UploadFile = File(...)): | |
| image = Image.open(io.BytesIO(await file.read())).convert("RGB") | |
| input_data = preprocess(image) | |
| prediction = model.predict(input_data) | |
| return { | |
| "prediction": prediction.tolist() | |
| } |