|
import tensorflow as tf |
|
import keras |
|
import gradio as gr |
|
import numpy as np |
|
import cv2 |
|
import os |
|
|
|
model=tf.keras.models.load_model('model.h5') |
|
|
|
def predict_pneumonia(image): |
|
resized_img = cv2.resize(image, (180, 180)) |
|
img_array = np.array(resized_img).reshape((1, 180, 180, 3)) |
|
|
|
prediction = model.predict(img_array)[0][0] |
|
pneumonia_percent = prediction*1 |
|
normal_percent = (1 - prediction)*1 |
|
return {"Pneumonia ": pneumonia_percent, "Normal ": normal_percent} |
|
|
|
inputs = gr.inputs.Image(shape=(180, 180)) |
|
outputs = gr.outputs.Label(num_top_classes=2) |
|
gradio_interface = gr.Interface(fn=predict_pneumonia, inputs=inputs, outputs=outputs, |
|
title="Classification of pneumonia in chest X-ray", |
|
|
|
examples = ["person1946_bacteria_4875.jpeg", "person1952_bacteria_4883.jpeg", "NORMAL2-IM-1427-0001.jpeg", "NORMAL2-IM-1431-0001.jpeg"], |
|
article = "<p style='text-align: center'>Lior Cohen & Arad Peleg | Final Project 2023</p>" |
|
"<p style='text-align: center'>Supervisor: Dr. Dima Alberg</p>", |
|
theme = gr.themes.Monochrome(),) |
|
|
|
|
|
|
|
|
|
|
|
gradio_interface.launch() |
|
|
|
|
|
|