import gradio as gr from tensorflow.keras.models import load_model from PIL import Image import numpy as np model = load_model('xray_image_classifier_model.keras') def predict_image(img): img = img.resize((150, 150)) img = np.array(img) / 255.0 img = np.expand_dims(img, axis=0) prediction = model.predict(img) label = 'Pneumonia' if prediction > 0.5 else 'Normal' return label iface = gr.Interface( fn=predict_image, inputs=gr.inputs.Image(type="pil"), outputs="text", title="X-ray Image Classifier", description="Upload an X-ray image to classify it as 'Pneumonia' or 'Normal'." ) iface.launch()