psinha823 commited on
Commit
aa671f0
·
verified ·
1 Parent(s): fd472ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -13,18 +13,21 @@ classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma',
13
 
14
  # Function to preprocess the uploaded image and make predictions
15
  def predict(img):
16
- img = img.resize((224, 224))
17
- img_array = tf.keras.preprocessing.image.img_to_array(img)
18
- img_array = tf.expand_dims(img_array, 0)
 
 
 
 
 
 
 
 
19
 
20
- predictions = model.predict(img_array)
21
- class_labels = classes
22
- # predictions = model.predict(img_array)
23
- # predicted_class = classes[np.argmax(predictions[0])]
24
- score = tf.nn.softmax(predictions[0])
25
- print(f"{class_labels[tf.argmax(score)]}")
26
-
27
- return f"{class_labels[tf.argmax(score)]}
28
 
29
  # Create a Gradio interface
30
  iface = gr.Interface(
 
13
 
14
  # Function to preprocess the uploaded image and make predictions
15
  def predict(img):
16
+ try:
17
+ img = img.resize((224, 224))
18
+ img_array = tf.keras.preprocessing.image.img_to_array(img)
19
+ img_array = tf.expand_dims(img_array, 0)
20
+
21
+ predictions = model.predict(img_array)
22
+ class_labels = classes
23
+ # predictions = model.predict(img_array)
24
+ # predicted_class = classes[np.argmax(predictions[0])]
25
+ score = tf.nn.softmax(predictions[0])
26
+ # print(f"{class_labels[tf.argmax(score)]}")
27
 
28
+ return f"Prediction: {class_labels[tf.argmax(score)]}"
29
+ except Exception as e:
30
+ return str(e)
 
 
 
 
 
31
 
32
  # Create a Gradio interface
33
  iface = gr.Interface(