Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Model yükleme
|
7 |
+
model = tf.keras.models.load_model("face_shape_model.h5")
|
8 |
+
|
9 |
+
# FastAPI başlat
|
10 |
+
app = FastAPI()
|
11 |
+
|
12 |
+
# Görsel veriyi tahmin için işleme
|
13 |
+
def preprocess_image(image):
|
14 |
+
image = image.resize((224, 224)) # Model input boyutuna göre değiştir
|
15 |
+
image = np.array(image) / 255.0 # Normalize et
|
16 |
+
image = np.expand_dims(image, axis=0) # Batch boyutunu ekle
|
17 |
+
return image
|
18 |
+
|
19 |
+
@app.post("/predict/")
|
20 |
+
async def predict(file: UploadFile = File(...)):
|
21 |
+
# Dosyayı oku ve işleme
|
22 |
+
image = Image.open(file.file)
|
23 |
+
processed_image = preprocess_image(image)
|
24 |
+
prediction = model.predict(processed_image)
|
25 |
+
predicted_class = np.argmax(prediction, axis=1)[0] # En yüksek olasılıklı sınıfı al
|
26 |
+
return {"predicted_class": int(predicted_class)}
|