|
from fastapi import FastAPI, File, UploadFile |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
model = tf.keras.models.load_model("face_shape_model.h5") |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
def preprocess_image(image): |
|
image = image.resize((224, 224)) |
|
image = np.array(image) / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
return image |
|
|
|
@app.post("/predict/") |
|
async def predict(file: UploadFile = File(...)): |
|
|
|
image = Image.open(file.file) |
|
processed_image = preprocess_image(image) |
|
prediction = model.predict(processed_image) |
|
predicted_class = np.argmax(prediction, axis=1)[0] |
|
return {"predicted_class": int(predicted_class)} |
|
|