Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
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)
|