psinha823 commited on
Commit
8335dff
·
verified ·
1 Parent(s): d583a25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -39,7 +39,7 @@ from tensorflow.keras.preprocessing import image
39
  import numpy as np
40
 
41
  # Load the trained model
42
- model = r'./model12_acc99_kera.h5'
43
 
44
  # Define the class names
45
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
@@ -48,27 +48,25 @@ classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma',
48
  def predict(img):
49
  # Resize and preprocess the image
50
  img = img.resize((224, 224))
51
- # img_array = image.img_to_array(img)
52
- # img_array = np.expand_dims(img_array, axis=0)
53
- # img_array = img_array / 255.0 # Normalize the image
54
- # img = image.resize((224,224))
55
- img_array = tf.keras.preprocessing.image.img_to_array(img)
56
- img_array = tf.expand_dims(img_array, 0)
57
-
58
  # Make predictions
59
  predictions = model.predict(img_array)
60
- print(f"Predictions: {predictions}") # Debug: Print the raw prediction values
61
-
62
  predicted_class_index = np.argmax(predictions[0])
63
  predicted_class = classes[predicted_class_index]
64
 
65
- return predicted_class
 
66
 
67
  # Create a Gradio interface
68
  iface = gr.Interface(
69
  fn=predict,
70
  inputs=gr.Image(type='pil'),
71
- outputs=gr.Textbox(label="Prediction"),
 
 
 
72
  title="Lung and Colon Cancer Detection",
73
  description="Upload an image of histopathological tissue to detect if it is a type of lung or colon cancer."
74
  )
 
39
  import numpy as np
40
 
41
  # Load the trained model
42
+ model = tf.keras.models.load_model('./model12_acc99_kera.h5')
43
 
44
  # Define the class names
45
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
 
48
  def predict(img):
49
  # Resize and preprocess the image
50
  img = img.resize((224, 224))
51
+ img_array = image.img_to_array(img)
52
+ img_array = np.expand_dims(img_array, axis=0)
53
+
 
 
 
 
54
  # Make predictions
55
  predictions = model.predict(img_array)
 
 
56
  predicted_class_index = np.argmax(predictions[0])
57
  predicted_class = classes[predicted_class_index]
58
 
59
+ # Return the predicted class and the raw predictions
60
+ return predicted_class, predictions[0]
61
 
62
  # Create a Gradio interface
63
  iface = gr.Interface(
64
  fn=predict,
65
  inputs=gr.Image(type='pil'),
66
+ outputs=[
67
+ gr.Textbox(label="Prediction"),
68
+ gr.Label(label="Raw Predictions")
69
+ ],
70
  title="Lung and Colon Cancer Detection",
71
  description="Upload an image of histopathological tissue to detect if it is a type of lung or colon cancer."
72
  )