File size: 1,607 Bytes
ae2057d
 
8d7e015
ae2057d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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",                                
                                #description = "A simple app to classify chest X-ray images into normal and pneumonia and show the percentage of each",                                                           
                                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(),)

# gr.themes.Soft() כחול
# gr.themes.Monochrome() שחור
# gr.themes.Glass() אפור

gradio_interface.launch()
# share=True
# live=True
# enable_queue=True