Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import tensorflow as tf
|
3 |
from tensorflow.keras.models import load_model
|
4 |
from tensorflow.keras.layers import Layer
|
|
|
|
|
5 |
|
6 |
# Define the custom 'FixedDropout' layer
|
7 |
class FixedDropout(Layer):
|
@@ -29,7 +31,18 @@ class_labels = ["Normal", "Cataract"]
|
|
29 |
|
30 |
# Define a function for prediction
|
31 |
def predict(image):
|
32 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Create the Gradio interface
|
35 |
gr.Interface(
|
|
|
2 |
import tensorflow as tf
|
3 |
from tensorflow.keras.models import load_model
|
4 |
from tensorflow.keras.layers import Layer
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
|
8 |
# Define the custom 'FixedDropout' layer
|
9 |
class FixedDropout(Layer):
|
|
|
31 |
|
32 |
# Define a function for prediction
|
33 |
def predict(image):
|
34 |
+
# Preprocess the input image
|
35 |
+
image = image.resize((224, 224)) # Adjust the size as needed
|
36 |
+
image = np.array(image) / 255.0 # Normalize pixel values
|
37 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
38 |
+
|
39 |
+
# Make a prediction using the loaded TensorFlow model
|
40 |
+
predictions = tf_model.predict(image)
|
41 |
+
|
42 |
+
# Get the predicted class label
|
43 |
+
predicted_label = class_labels[np.argmax(predictions)]
|
44 |
+
|
45 |
+
return predicted_label
|
46 |
|
47 |
# Create the Gradio interface
|
48 |
gr.Interface(
|