import gradio as gr import tensorflow as tf import numpy as np import json from PIL import Image # 1. Load Model EfficientNet # Ganti nama file sesuai dengan file .h5 efficientnet kamu model = tf.keras.models.load_model("efficientnet_b3_isic2019.h5") # 2. Load Label with open("class_indices.json", "r") as f: class_indices = json.load(f) labels = {v: k for k, v in class_indices.items()} # 3. Fungsi Preprocessing def predict_image(img): img = img.resize((300, 300)) img_array = np.array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) preds = model.predict(img_array)[0] confidences = {} for i, label in labels.items(): if i < len(preds): confidences[label] = float(preds[i]) predicted_class = max(confidences, key=confidences.get) confidence = confidences[predicted_class] return { "predicted_class": predicted_class, "confidence": confidence, "confidences": confidences } # 4. Interface Gradio iface = gr.Interface( fn=predict_image, inputs=gr.Image(type="pil"), outputs=gr.JSON(), title="Skin Disease Detection - EfficientNet", description="Deteksi penyakit kulit menggunakan model EfficientNet." ) iface.launch()