piyushmadhukar commited on
Commit
c589552
·
verified ·
1 Parent(s): 31d5c3a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app2.py +54 -0
  2. breast_cancer_detection_model5.h5 +3 -0
app2.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import cv2 # Ensure you have opencv-python installed
4
+ from tensorflow.keras.models import load_model # Ensure you have TensorFlow installed
5
+
6
+ IMG_SIZE = 128 # Image size for the model input
7
+
8
+ # Load your trained model
9
+ model = load_model(r'breast_cancer_detection_model5.h5') # Update this path to your actual model file
10
+
11
+ # Define class names according to your model
12
+ class_names = ['benign', 'malignant', 'normal'] # Update this list if different
13
+
14
+ # Define the prediction function
15
+ def predict_cancer(images):
16
+ results = []
17
+ for img in images:
18
+ # Convert image to grayscale (if it's not already), resize, and normalize
19
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) # Convert to grayscale if not already
20
+ img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize to match model input
21
+ img = np.expand_dims(img, axis=-1) # Add channel dimension
22
+ img = img / 255.0 # Normalize
23
+ img = np.expand_dims(img, axis=0) # Add batch dimension
24
+
25
+ # Make prediction
26
+ prediction = model.predict(img)
27
+ class_idx = np.argmax(prediction[0])
28
+ class_name = class_names[class_idx]
29
+ probability = np.max(prediction[0])
30
+ results.append(f"{class_name} (Probability: {probability:.2f})")
31
+
32
+ return results
33
+
34
+ # Define Gradio interface
35
+ def classify_images(images):
36
+ if not isinstance(images, list): # Ensure images is a list of images
37
+ images = [images]
38
+ return predict_cancer(images)
39
+
40
+ # Define the Gradio interface
41
+ input_images = gr.Image(type='numpy', label='Upload Ultrasound Images')
42
+ output_labels = gr.Textbox(label='Predictions')
43
+
44
+ gr_interface = gr.Interface(
45
+ fn=classify_images,
46
+ inputs=input_images,
47
+ outputs=output_labels,
48
+ title="Breast Cancer Detection from Ultrasound Images",
49
+ description="Upload multiple breast ultrasound images to get predictions on whether they show benign, malignant, or normal conditions."
50
+ )
51
+
52
+ # Launch the Gradio app
53
+ if __name__ == "__main__":
54
+ gr_interface.launch()
breast_cancer_detection_model5.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8aa49401e6dc58a02a9476b5865eaea3db31dc2f44f122211f0fdd1f01a9172c
3
+ size 39706832