Elegbede commited on
Commit
f14de50
1 Parent(s): cc92474

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -5,7 +5,7 @@ import numpy as np
5
  from tensorflow.keras.preprocessing import image
6
 
7
 
8
- def predict_image(input_image):
9
  # Load and preprocess the input image
10
  img = image.load_img(input_image, target_size=(224, 224))
11
  img = image.img_to_array(img)
@@ -17,12 +17,16 @@ def predict_image(input_image):
17
  loaded_model = load_model('tumor_model.h5')
18
  predictions = loaded_model.predict(img)
19
 
20
- # Assuming it's a binary classification model, you can interpret the prediction
21
- class_names = ['yes', 'no']
22
- class_index = int(round(predictions[0][0]))
23
- class_name = class_names[class_index]
 
 
 
 
24
 
25
  return f'Predicted Class: {class_name}'
26
 
27
- iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")
28
  iface.launch(share=True)
 
5
  from tensorflow.keras.preprocessing import image
6
 
7
 
8
+ def predict_image(input_image, threshold=0.5):
9
  # Load and preprocess the input image
10
  img = image.load_img(input_image, target_size=(224, 224))
11
  img = image.img_to_array(img)
 
17
  loaded_model = load_model('tumor_model.h5')
18
  predictions = loaded_model.predict(img)
19
 
20
+ # Assuming it's a binary classification model
21
+ predicted_probability = predictions[0][0]
22
+
23
+ # Determine the class based on the threshold
24
+ if predicted_probability > threshold:
25
+ class_name = 'tumor'
26
+ else:
27
+ class_name = 'no tumor'
28
 
29
  return f'Predicted Class: {class_name}'
30
 
31
+ iface = gr.Interface(fn=predict_image, inputs="image", outputs="text", live=True)
32
  iface.launch(share=True)