psinha823 commited on
Commit
d652d7f
·
verified ·
1 Parent(s): 60e6d39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -3
app.py CHANGED
@@ -1,23 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
  # Load the trained model
7
- model = tf.keras.models.load_model('./model12_acc99_kera.h5')
8
 
9
  # Define the class names
10
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
11
 
12
  # Function to preprocess the uploaded image and make predictions
13
  def predict(img):
 
14
  img = img.resize((224, 224))
15
  img_array = image.img_to_array(img)
16
  img_array = np.expand_dims(img_array, axis=0)
17
  img_array = img_array / 255.0 # Normalize the image
18
 
 
19
  predictions = model.predict(img_array)
20
- predicted_class = classes[np.argmax(predictions[0])]
 
 
 
21
 
22
  return predicted_class
23
 
@@ -32,4 +72,3 @@ iface = gr.Interface(
32
 
33
  # Launch the interface
34
  iface.launch()
35
-
 
1
+ # import gradio as gr
2
+ # import tensorflow as tf
3
+ # from tensorflow.keras.preprocessing import image
4
+ # import numpy as np
5
+
6
+ # # Load the trained model
7
+ # model = tf.keras.models.load_model('./model12_acc99_kera.h5')
8
+
9
+ # # Define the class names
10
+ # classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
11
+
12
+ # # Function to preprocess the uploaded image and make predictions
13
+ # def predict(img):
14
+ # img = img.resize((224, 224))
15
+ # img_array = image.img_to_array(img)
16
+ # img_array = np.expand_dims(img_array, axis=0)
17
+ # img_array = img_array / 255.0 # Normalize the image
18
+
19
+ # predictions = model.predict(img_array)
20
+ # predicted_class = classes[np.argmax(predictions[0])]
21
+
22
+ # return predicted_class
23
+
24
+ # # Create a Gradio interface
25
+ # iface = gr.Interface(
26
+ # fn=predict,
27
+ # inputs=gr.Image(type='pil'),
28
+ # outputs=gr.Textbox(label="Prediction"),
29
+ # title="Lung and Colon Cancer Detection",
30
+ # description="Upload an image of histopathological tissue to detect if it is a type of lung or colon cancer."
31
+ # )
32
+
33
+ # # Launch the interface
34
+ # iface.launch()
35
+
36
  import gradio as gr
37
  import tensorflow as tf
38
  from tensorflow.keras.preprocessing import image
39
  import numpy as np
40
 
41
  # Load the trained model
42
+ model = tf.keras.models.load_model('path/to/your/saved_model')
43
 
44
  # Define the class names
45
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
46
 
47
  # Function to preprocess the uploaded image and make predictions
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
 
55
+ # Make predictions
56
  predictions = model.predict(img_array)
57
+ print(f"Predictions: {predictions}") # Debug: Print the raw prediction values
58
+
59
+ predicted_class_index = np.argmax(predictions[0])
60
+ predicted_class = classes[predicted_class_index]
61
 
62
  return predicted_class
63
 
 
72
 
73
  # Launch the interface
74
  iface.launch()