Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
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()
|