Elegbede commited on
Commit
2454e6f
1 Parent(s): bd97a52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -7,13 +7,16 @@ from tensorflow.keras.preprocessing import image
7
  model = tf.keras.models.load_model('Tumor_Model.h5')
8
 
9
  def predict_input_image(img):
10
- # Ensure the image is in the right shape and format
11
- img = img.reshape((1, 224, 224, 3))
12
- img = tf.keras.applications.vgg16.preprocess_input(img)
 
 
 
13
  # Make predictions
14
- prediction = model.predict(img).flatten()
15
  result = 'No Tumor Detected' if prediction[0][0] > 0.5 else 'Tumor detected'
16
-
17
  return f"Prediction: {result}"
18
 
19
  # Define Gradio interface
@@ -24,4 +27,4 @@ iface = gr.Interface(
24
  )
25
 
26
  # Launch the interface
27
- iface.launch()
 
7
  model = tf.keras.models.load_model('Tumor_Model.h5')
8
 
9
  def predict_input_image(img):
10
+ # Convert NumPy array to PIL.Image
11
+ img = Image.fromarray(np.uint8(img))
12
+ img = img.convert('RGB')
13
+ img = img.resize((224, 224))
14
+ img = np.array(img).reshape(1, 224, 224, 3) # Reshape the image to match the model input
15
+
16
  # Make predictions
17
+ prediction = model.predict(img)
18
  result = 'No Tumor Detected' if prediction[0][0] > 0.5 else 'Tumor detected'
19
+
20
  return f"Prediction: {result}"
21
 
22
  # Define Gradio interface
 
27
  )
28
 
29
  # Launch the interface
30
+ iface.launch(debug = True)