Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ def predict_pneumonia(image):
|
|
18 |
prediction = model.predict(img_array)[0][0]
|
19 |
|
20 |
# Use a more robust threshold for determining whether an image has pneumonia
|
21 |
-
threshold = 0.
|
22 |
|
23 |
if prediction >= threshold:
|
24 |
pneumonia_prediction = 1
|
@@ -31,13 +31,18 @@ def predict_pneumonia(image):
|
|
31 |
# Return the top two possible classifications
|
32 |
top_classes = model.predict_classes(img_array)
|
33 |
|
|
|
|
|
|
|
|
|
34 |
return {
|
35 |
"Pneumonia": pneumonia_prediction,
|
36 |
"Class probabilities": class_probabilities,
|
37 |
-
"Top classes": top_classes
|
|
|
|
|
38 |
}
|
39 |
|
40 |
-
|
41 |
inputs = gr.inputs.Image(shape=(180, 180))
|
42 |
outputs = gr.outputs.Label(num_top_classes=2)
|
43 |
|
@@ -45,8 +50,8 @@ gradio_interface = gr.Interface(
|
|
45 |
fn=predict_pneumonia,
|
46 |
inputs=inputs,
|
47 |
outputs=outputs,
|
48 |
-
title="
|
49 |
-
description="
|
50 |
examples=[
|
51 |
["person1946_bacteria_4875.jpeg"],
|
52 |
["person1952_bacteria_4883.jpeg"],
|
@@ -54,6 +59,8 @@ gradio_interface = gr.Interface(
|
|
54 |
["NORMAL2-IM-1431-0001.jpeg"]
|
55 |
],
|
56 |
theme="default",
|
|
|
57 |
)
|
58 |
|
|
|
59 |
gradio_interface.launch()
|
|
|
18 |
prediction = model.predict(img_array)[0][0]
|
19 |
|
20 |
# Use a more robust threshold for determining whether an image has pneumonia
|
21 |
+
threshold = 0.5
|
22 |
|
23 |
if prediction >= threshold:
|
24 |
pneumonia_prediction = 1
|
|
|
31 |
# Return the top two possible classifications
|
32 |
top_classes = model.predict_classes(img_array)
|
33 |
|
34 |
+
# Return the class names and the confidence scores for each class
|
35 |
+
class_names = ["Pneumonia", "Normal"]
|
36 |
+
confidence_scores = class_probabilities
|
37 |
+
|
38 |
return {
|
39 |
"Pneumonia": pneumonia_prediction,
|
40 |
"Class probabilities": class_probabilities,
|
41 |
+
"Top classes": top_classes,
|
42 |
+
"Class names": class_names,
|
43 |
+
"Confidence scores": confidence_scores
|
44 |
}
|
45 |
|
|
|
46 |
inputs = gr.inputs.Image(shape=(180, 180))
|
47 |
outputs = gr.outputs.Label(num_top_classes=2)
|
48 |
|
|
|
50 |
fn=predict_pneumonia,
|
51 |
inputs=inputs,
|
52 |
outputs=outputs,
|
53 |
+
title="Pneumonia X-Ray Classification API",
|
54 |
+
description="This API classifies images of chest X-rays as having pneumonia or being normal.",
|
55 |
examples=[
|
56 |
["person1946_bacteria_4875.jpeg"],
|
57 |
["person1952_bacteria_4883.jpeg"],
|
|
|
59 |
["NORMAL2-IM-1431-0001.jpeg"]
|
60 |
],
|
61 |
theme="default",
|
62 |
+
allow_uploads=True
|
63 |
)
|
64 |
|
65 |
+
|
66 |
gradio_interface.launch()
|