Spaces:
No application file
No application file
| import gradio as gr | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.applications.densenet import preprocess_input | |
| from PIL import Image | |
| import numpy as np | |
| # Ukuran gambar dan load model | |
| IMG_SIZE = (224, 224) | |
| model = load_model("xray_class.weights.h5") | |
| # Preprocessing | |
| def preprocess_image(image): | |
| image = image.convert("RGB") | |
| image = image.resize(IMG_SIZE) | |
| image = np.array(image) | |
| image = preprocess_input(image) | |
| image = np.expand_dims(image, axis=0) | |
| return image | |
| # Label sesuai model kamu (ganti sesuai penyakit yang kamu latih) | |
| label_names = ["Infiltration", "Effusion", "Atelectasis"] | |
| # Fungsi prediksi | |
| def predict(image): | |
| img = preprocess_image(image) | |
| pred = model.predict(img)[0] | |
| result = {label: float(f"{val:.2f}") for label, val in zip(label_names, pred)} | |
| return result | |
| # Interface | |
| interface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="label") | |
| if __name__ == "__main__": | |
| interface.launch() | |