| import gradio as gr
|
| import tensorflow as tf
|
| import numpy as np
|
| from PIL import Image
|
|
|
|
|
| model = tf.keras.models.load_model("skin_type_model.keras")
|
|
|
|
|
| class_names = ["Berminyak", "Normal", "Kering"]
|
|
|
|
|
|
|
| def preprocess_image(img):
|
| img = img.resize((224, 224))
|
| img = np.array(img) / 255.0
|
| img = np.expand_dims(img, axis=0)
|
| return img
|
|
|
|
|
|
|
| def classify_img(image):
|
| image = preprocess_image(image)
|
| prediction = model.predict(image)[0]
|
| probabilities = {
|
| class_names[i]: float(prediction[i]) for i in range(len(class_names))
|
| }
|
| return probabilities
|
|
|
|
|
|
|
| interface = gr.Interface(
|
| fn=classify_img,
|
| inputs=gr.Image(type="pil"),
|
| outputs=gr.Label(num_top_classes=3),
|
| title="Klasifikasi Jenis Kulit Wajah",
|
| description="Upload gambar wajah untuk mengklasifikasikan jenis kulit menjadi: Berminyak, Normal, atau Kering.",
|
| )
|
|
|
| interface.launch()
|
|
|