FaceShape / app.py
fatyidha's picture
Create app.py
2fed88f verified
from fastapi import FastAPI, File, UploadFile
import tensorflow as tf
from PIL import Image
import numpy as np
# Model yükleme
model = tf.keras.models.load_model("face_shape_model.h5")
# FastAPI başlat
app = FastAPI()
# Görsel veriyi tahmin için işleme
def preprocess_image(image):
image = image.resize((224, 224)) # Model input boyutuna göre değiştir
image = np.array(image) / 255.0 # Normalize et
image = np.expand_dims(image, axis=0) # Batch boyutunu ekle
return image
@app.post("/predict/")
async def predict(file: UploadFile = File(...)):
# Dosyayı oku ve işleme
image = Image.open(file.file)
processed_image = preprocess_image(image)
prediction = model.predict(processed_image)
predicted_class = np.argmax(prediction, axis=1)[0] # En yüksek olasılıklı sınıfı al
return {"predicted_class": int(predicted_class)}