Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,21 +19,24 @@ def predict_xray(image):
|
|
| 19 |
image = image.reshape(1, 150, 150, 3) / 255.0 # Normalization (if used in training)
|
| 20 |
|
| 21 |
# Make prediction
|
| 22 |
-
prediction = model.predict(image)
|
| 23 |
-
prediction = prediction.argmax() # Get class with highest probability
|
| 24 |
|
| 25 |
-
# Class labels
|
| 26 |
-
labels = ["Normal", "Pneumonia"]
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Create Gradio UI
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=predict_xray,
|
| 33 |
inputs=gr.Image(type="pil"), # Accepts image input
|
| 34 |
-
outputs="text", # Returns class label
|
| 35 |
title="Pneumonia Detection",
|
| 36 |
-
description="Upload a chest X-ray image, and the model will predict if the patient has pneumonia or is normal."
|
| 37 |
)
|
| 38 |
|
| 39 |
# Launch the app
|
|
|
|
| 19 |
image = image.reshape(1, 150, 150, 3) / 255.0 # Normalization (if used in training)
|
| 20 |
|
| 21 |
# Make prediction
|
| 22 |
+
prediction = model.predict(image)[0] # Get probabilities for both classes
|
|
|
|
| 23 |
|
| 24 |
+
# Class labels
|
| 25 |
+
labels = ["The Patient is Normal.", "The Patient has Pneumonia."]
|
| 26 |
|
| 27 |
+
# Get predicted class and confidence scores
|
| 28 |
+
predicted_class = np.argmax(prediction) # Class with highest probability
|
| 29 |
+
confidence = prediction[predicted_class] * 100 # Convert to percentage
|
| 30 |
+
|
| 31 |
+
return f"{labels[predicted_class]} ({confidence:.2f}% confidence)"
|
| 32 |
|
| 33 |
# Create Gradio UI
|
| 34 |
iface = gr.Interface(
|
| 35 |
fn=predict_xray,
|
| 36 |
inputs=gr.Image(type="pil"), # Accepts image input
|
| 37 |
+
outputs="text", # Returns class label with confidence
|
| 38 |
title="Pneumonia Detection",
|
| 39 |
+
description="Upload a chest X-ray image, and the model will predict if the patient has pneumonia or is normal, along with confidence scores."
|
| 40 |
)
|
| 41 |
|
| 42 |
# Launch the app
|