Snigs98 commited on
Commit
3d100de
·
verified ·
1 Parent(s): 71b13ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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.cvtColor(img, cv2.COLOR_BGR2RGB)
14
- img = cv2.resize(img, (150, 150)) / 255.0
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."