|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
pneumonia_model = tf.keras.models.load_model("pneumonia_model.h5") |
|
|
|
|
|
def predict_pneumonia(image_path): |
|
|
img = Image.open(image_path).convert("RGB").resize((128, 128)) |
|
|
img_array = np.array(img) / 255.0 |
|
|
img_array = np.expand_dims(img_array, axis=0) |
|
|
|
|
|
prediction = pneumonia_model.predict(img_array) |
|
|
return "Positive" if prediction[0][0] > 0.5 else "Negative" |
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=predict_pneumonia, |
|
|
inputs=gr.Image(type="filepath"), |
|
|
outputs="text", |
|
|
title="Pneumonia Prediction", |
|
|
description="Upload an image to get a pneumonia prediction." |
|
|
) |
|
|
|
|
|
|
|
|
interface.launch() |
|
|
|