Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,9 @@ class_labels = ["NORMAL", "PNEUMONIA"] # Update if you have more classes
|
|
| 10 |
|
| 11 |
# Preprocessing function for uploaded images
|
| 12 |
def preprocess_image(img):
|
| 13 |
-
img = cv2.
|
| 14 |
-
img =
|
| 15 |
-
img = np.expand_dims(img, axis=0)
|
| 16 |
return img
|
| 17 |
|
| 18 |
# Prediction function
|
|
@@ -26,7 +26,7 @@ def predict_chest_xray(img):
|
|
| 26 |
# Create Gradio UI
|
| 27 |
interface = gr.Interface(
|
| 28 |
fn=predict_chest_xray,
|
| 29 |
-
inputs=gr.Image(type="numpy"),
|
| 30 |
outputs="text",
|
| 31 |
title="Chest X-Ray Diagnosis",
|
| 32 |
description="Upload a chest X-ray image to get a diagnosis prediction."
|
|
|
|
| 10 |
|
| 11 |
# Preprocessing function for uploaded images
|
| 12 |
def preprocess_image(img):
|
| 13 |
+
img = cv2.resize(img, (150, 150)) # Resize
|
| 14 |
+
img = img.astype(np.float32) / 255.0 # Normalize and ensure dtype
|
| 15 |
+
img = np.expand_dims(img, axis=0) # Add batch dimension
|
| 16 |
return img
|
| 17 |
|
| 18 |
# Prediction function
|
|
|
|
| 26 |
# Create Gradio UI
|
| 27 |
interface = gr.Interface(
|
| 28 |
fn=predict_chest_xray,
|
| 29 |
+
inputs=gr.Image(type="numpy"), # Expect NumPy array
|
| 30 |
outputs="text",
|
| 31 |
title="Chest X-Ray Diagnosis",
|
| 32 |
description="Upload a chest X-ray image to get a diagnosis prediction."
|