Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,36 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
model
|
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 |
-
prediction = {
|
36 |
-
class_names[0]: float(confidence[0]),
|
37 |
-
class_names[1]: float(confidence[1])
|
38 |
-
}
|
39 |
-
|
40 |
-
return prediction
|
41 |
-
|
42 |
-
# Create the Gradio interface
|
43 |
-
iface = gr.Interface(
|
44 |
-
fn=predict,
|
45 |
-
inputs=gr.inputs.Image(type="pil", label="Input Image"),
|
46 |
-
outputs=gr.outputs.Label(num_top_classes=2, label="Predicted Class"),
|
47 |
-
title="Pneumonia Detector 馃憗",
|
48 |
-
description="A ResNet101 computer vision model to detect pneumonia",
|
49 |
-
article="Please add a chest X-Ray image"
|
50 |
-
)
|
51 |
-
|
52 |
-
# Launch the interface
|
53 |
-
iface.launch()
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import keras
|
3 |
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import cv2
|
6 |
+
import os
|
7 |
+
|
8 |
+
model=tf.keras.models.load_model('model.h5')
|
9 |
+
|
10 |
+
def predict_pneumonia(image):
|
11 |
+
resized_img = cv2.resize(image, (180, 180))
|
12 |
+
img_array = np.array(resized_img).reshape((1, 180, 180, 3))
|
13 |
+
|
14 |
+
prediction = model.predict(img_array)[0][0]
|
15 |
+
pneumonia_percent = prediction*1
|
16 |
+
normal_percent = (1 - prediction)*1
|
17 |
+
return {"Pneumonia ": pneumonia_percent, "Normal ": normal_percent}
|
18 |
+
|
19 |
+
inputs = gr.inputs.Image(shape=(180, 180))
|
20 |
+
outputs = gr.outputs.Label(num_top_classes=2)
|
21 |
+
gradio_interface = gr.Interface(fn=predict_pneumonia, inputs=inputs, outputs=outputs,
|
22 |
+
title="Classification of pneumonia in chest X-ray",
|
23 |
+
#description = "A simple app to classify chest X-ray images into normal and pneumonia and show the percentage of each",
|
24 |
+
examples = ["person1946_bacteria_4875.jpeg", "person1952_bacteria_4883.jpeg", "NORMAL2-IM-1427-0001.jpeg", "NORMAL2-IM-1431-0001.jpeg"],
|
25 |
+
article = "<p style='text-align: center'>Lior Cohen & Arad Peleg | Final Project 2023</p>"
|
26 |
+
"<p style='text-align: center'>Supervisor: Dr. Dima Alberg</p>",
|
27 |
+
theme = gr.themes.Monochrome(),)
|
28 |
+
|
29 |
+
# gr.themes.Soft() 讻讞讜诇
|
30 |
+
# gr.themes.Monochrome() 砖讞讜专
|
31 |
+
# gr.themes.Glass() 讗驻讜专
|
32 |
+
|
33 |
+
gradio_interface.launch()
|
34 |
+
# share=True
|
35 |
+
# live=True
|
36 |
+
# enable_queue=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|