Update app.py
Browse files
app.py
CHANGED
@@ -17,23 +17,25 @@ def preprocess_image(image):
|
|
17 |
|
18 |
# Prediction function
|
19 |
def predict(image):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
# Gradio interface
|
27 |
interface = gr.Interface(
|
28 |
fn=predict,
|
29 |
-
inputs=gr.Image(type="pil"),
|
30 |
-
outputs="
|
31 |
-
title="Pneumonia Detection from Chest X-rays",
|
32 |
-
description="Upload a chest X-ray image to detect if the person has pneumonia.",
|
33 |
-
theme="
|
34 |
allow_flagging="never"
|
35 |
)
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
interface.launch()
|
|
|
17 |
|
18 |
# Prediction function
|
19 |
def predict(image):
|
20 |
+
try:
|
21 |
+
image_array = preprocess_image(image)
|
22 |
+
prediction = model.predict(image_array)[0][0]
|
23 |
+
label = "Pneumonia" if prediction > 0.5 else "Normal"
|
24 |
+
confidence = prediction if prediction > 0.5 else 1 - prediction
|
25 |
+
return f"{label} ({confidence * 100:.2f}% confidence)"
|
26 |
+
except Exception as e:
|
27 |
+
return f"Error: {str(e)}"
|
28 |
|
29 |
# Gradio interface
|
30 |
interface = gr.Interface(
|
31 |
fn=predict,
|
32 |
+
inputs=gr.Image(type="pil", label="Upload Chest X-ray"),
|
33 |
+
outputs=gr.Textbox(label="Prediction"),
|
34 |
+
title="🫁 Pneumonia Detection from Chest X-rays",
|
35 |
+
description="Upload a chest X-ray image to detect if the person has pneumonia using a deep learning model.",
|
36 |
+
theme="default",
|
37 |
allow_flagging="never"
|
38 |
)
|
39 |
|
40 |
+
# Important: Always call launch() outside of __main__ block on Hugging Face Spaces
|
41 |
+
interface.launch(debug=True)
|
|