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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,17 +1,23 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
4
- from tensorflow.keras.preprocessing import image
5
  import cv2
 
 
 
 
6
 
7
  # Load the trained model
8
- model = tf.keras.models.load_model("chest_xray_model.h5")
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.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
 
@@ -33,4 +39,4 @@ interface = gr.Interface(
33
  )
34
 
35
  if __name__ == "__main__":
36
- interface.launch()
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
 
4
  import cv2
5
+ import os
6
+
7
+ # Ensure correct class labels (fix folder naming issue if needed)
8
+ class_labels = ["COVID-19", "Normal", "Pneumonia"] # Ensure class order is correct
9
 
10
  # Load the trained model
11
+ model_path = "chest_xray_model.h5"
12
+ if not os.path.exists(model_path):
13
+ raise FileNotFoundError(f"Model file '{model_path}' not found. Ensure it's uploaded to the Space.")
14
+
15
+ model = tf.keras.models.load_model(model_path)
16
 
17
  # Preprocessing function for uploaded images
18
  def preprocess_image(img):
19
  img = cv2.resize(img, (150, 150)) # Resize
20
+ img = img.astype(np.float32) / 255.0 # Normalize pixel values
21
  img = np.expand_dims(img, axis=0) # Add batch dimension
22
  return img
23
 
 
39
  )
40
 
41
  if __name__ == "__main__":
42
+ interface.launch()