Application code
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
|
11 |
model = tf.keras.models.load_model("maheshbabu.h5")
|
12 |
|
13 |
# Define class labels
|
14 |
-
classes = ["Normal","Cancerous"]
|
15 |
|
16 |
# Prediction function
|
17 |
def predict(image):
|
@@ -26,7 +26,12 @@ def predict(image):
|
|
26 |
class_idx = np.argmax(predictions[0]) # Get index of highest probability
|
27 |
confidence = predictions[0][class_idx] # Get confidence score
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
except Exception as e:
|
31 |
return f"Error processing image: {str(e)}"
|
32 |
|
@@ -34,10 +39,10 @@ def predict(image):
|
|
34 |
interface = gr.Interface(
|
35 |
fn=predict,
|
36 |
inputs=gr.Image(type="filepath"), # Use filepath to pass the image path
|
37 |
-
outputs="
|
38 |
title="Blood Cancer Detection",
|
39 |
description="Upload an image to detect whether it is Normal or Cancerous."
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
-
interface.launch(server_port=7860, server_name="0.0.0.0", share=True)
|
|
|
11 |
model = tf.keras.models.load_model("maheshbabu.h5")
|
12 |
|
13 |
# Define class labels
|
14 |
+
classes = ["Normal", "Cancerous"]
|
15 |
|
16 |
# Prediction function
|
17 |
def predict(image):
|
|
|
26 |
class_idx = np.argmax(predictions[0]) # Get index of highest probability
|
27 |
confidence = predictions[0][class_idx] # Get confidence score
|
28 |
|
29 |
+
# Modify the output based on the prediction
|
30 |
+
if classes[class_idx] == "Normal":
|
31 |
+
return "No Cancer Found"
|
32 |
+
else:
|
33 |
+
return "Cancer Found!"
|
34 |
+
|
35 |
except Exception as e:
|
36 |
return f"Error processing image: {str(e)}"
|
37 |
|
|
|
39 |
interface = gr.Interface(
|
40 |
fn=predict,
|
41 |
inputs=gr.Image(type="filepath"), # Use filepath to pass the image path
|
42 |
+
outputs="text", # Change output type to "text" for customized message
|
43 |
title="Blood Cancer Detection",
|
44 |
description="Upload an image to detect whether it is Normal or Cancerous."
|
45 |
)
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
+
interface.launch(server_port=7860, server_name="0.0.0.0", share=True)
|