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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -46,18 +46,22 @@ classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma',
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
-
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(
@@ -72,4 +76,4 @@ iface = gr.Interface(
72
  )
73
 
74
  # Launch the interface
75
- iface.launch()
 
46
 
47
  # Function to preprocess the uploaded image and make predictions
48
  def predict(img):
49
+ try:
50
+ # Resize and preprocess the image
51
+ img = img.resize((224, 224))
52
+ img_array = image.img_to_array(img)
53
+ img_array = np.expand_dims(img_array, axis=0)
54
+
55
+ # Make predictions
56
+ predictions = model.predict(img_array)
57
+ predicted_class_index = np.argmax(predictions[0])
58
+ predicted_class = classes[predicted_class_index]
59
+
60
+ # Return the predicted class and the raw predictions
61
+ return predicted_class, predictions[0]
62
+ except Exception as e:
63
+ # Print the error message
64
+ return str(e), str(e)
65
 
66
  # Create a Gradio interface
67
  iface = gr.Interface(
 
76
  )
77
 
78
  # Launch the interface
79
+ iface.launch()