Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,25 +13,31 @@ model = tf.keras.models.load_model("best_model_weights.h5") # Replace with the
|
|
13 |
|
14 |
# Define the image classification function
|
15 |
def classify_image(input_image):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
return f"Predicted Class: {class_label} (Probability: {class_prob:.2f})"
|
35 |
|
36 |
# Define the Gradio interface
|
37 |
iface = gr.Interface(
|
|
|
13 |
|
14 |
# Define the image classification function
|
15 |
def classify_image(input_image):
|
16 |
+
try:
|
17 |
+
# Preprocess the input image
|
18 |
+
input_image = Image.open(BytesIO(input_image))
|
19 |
+
input_image = input_image.resize((img_width, img_height))
|
20 |
+
input_image = np.array(input_image) / 255.0 # Normalize pixel values
|
21 |
|
22 |
+
# Make a prediction using the model
|
23 |
+
predictions = model.predict(np.expand_dims(input_image, axis=0))
|
24 |
|
25 |
+
# Get the class label with the highest probability
|
26 |
+
class_index = np.argmax(predictions)
|
27 |
+
class_prob = predictions[0][class_index]
|
28 |
|
29 |
+
# Define class labels (you can replace these with your actual class labels)
|
30 |
+
class_labels = ["Normal", "Cataract"]
|
31 |
|
32 |
+
# Get the class label
|
33 |
+
class_label = class_labels[class_index]
|
34 |
+
|
35 |
+
return f"Predicted Class: {class_label} (Probability: {class_prob:.2f})"
|
36 |
+
except Exception as e:
|
37 |
+
return "Error: Invalid image file"
|
38 |
+
|
39 |
+
# ...
|
40 |
|
|
|
41 |
|
42 |
# Define the Gradio interface
|
43 |
iface = gr.Interface(
|