Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,39 @@
|
|
1 |
-
import tensorflow as tf
|
2 |
-
import keras
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import cv2
|
6 |
-
import
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
-
def
|
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*
|
16 |
-
normal_percent = (1 - prediction)*
|
17 |
-
return {"Pneumonia
|
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 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
gradio_interface.launch()
|
34 |
-
# share=True
|
35 |
-
# live=True
|
36 |
-
# enable_queue=True
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import cv2
|
4 |
+
import tensorflow as tf
|
5 |
|
6 |
+
# Carregar o modelo
|
7 |
+
model = tf.keras.models.load_model('model.h5')
|
8 |
|
9 |
+
def preprocess_image(image):
|
10 |
resized_img = cv2.resize(image, (180, 180))
|
11 |
+
img_array = np.array(resized_img).reshape((1, 180, 180, 3))
|
12 |
+
return img_array
|
13 |
|
14 |
+
def predict_pneumonia(image):
|
15 |
+
img_array = preprocess_image(image)
|
16 |
prediction = model.predict(img_array)[0][0]
|
17 |
+
pneumonia_percent = prediction * 100
|
18 |
+
normal_percent = (1 - prediction) * 100
|
19 |
+
return {"Pneumonia": pneumonia_percent, "Normal": normal_percent}
|
20 |
|
21 |
inputs = gr.inputs.Image(shape=(180, 180))
|
22 |
outputs = gr.outputs.Label(num_top_classes=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
gradio_interface = gr.Interface(
|
25 |
+
fn=predict_pneumonia,
|
26 |
+
inputs=inputs,
|
27 |
+
outputs=outputs,
|
28 |
+
title="Classifica莽茫o de Pneumonia em Raios-X de T贸rax",
|
29 |
+
description="Esta aplica莽茫o classifica imagens de raios-X de t贸rax em pneumonia e normal.",
|
30 |
+
examples=[
|
31 |
+
["person1946_bacteria_4875.jpeg"],
|
32 |
+
["person1952_bacteria_4883.jpeg"],
|
33 |
+
["NORMAL2-IM-1427-0001.jpeg"],
|
34 |
+
["NORMAL2-IM-1431-0001.jpeg"]
|
35 |
+
],
|
36 |
+
theme="default"
|
37 |
+
)
|
38 |
|
39 |
gradio_interface.launch()
|
|
|
|
|
|