segmentation / app.py
shekzee's picture
Update app.py
64a04e7 verified
raw
history blame
760 Bytes
from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from PIL import Image
from io import BytesIO
import numpy as np
import tensorflow as tf
app = FastAPI()
# CORS config (optional)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
contents = await file.read()
img = Image.open(BytesIO(contents)).convert("RGB")
img = img.resize((256, 256)) # or whatever your model expects
arr = np.array(img) / 255.0
arr = np.expand_dims(arr, 0)
# prediction = model.predict(arr)
# result = do_something_with_prediction(prediction)
return {"success": True}