Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
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(
|