Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
-
import requests
|
4 |
import cv2
|
5 |
import numpy as np
|
6 |
|
@@ -10,23 +9,22 @@ tf_model = tf.keras.models.load_model(tf_model_path)
|
|
10 |
|
11 |
class_labels = ["Normal", "Cataract"]
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
return
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
outputs=["label", "number"],
|
30 |
-
)
|
31 |
|
32 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
|
|
3 |
import cv2
|
4 |
import numpy as np
|
5 |
|
|
|
9 |
|
10 |
class_labels = ["Normal", "Cataract"]
|
11 |
|
12 |
+
# Define a Gradio interface
|
13 |
+
def classify_image(input_image):
|
14 |
+
# Preprocess the input image
|
15 |
+
input_image = cv2.resize(input_image, (224, 224)) # Resize the image to match the model's input size
|
16 |
+
input_image = np.expand_dims(input_image, axis=0) # Add batch dimension
|
17 |
+
input_image = input_image / 255.0 # Normalize pixel values (assuming input range [0, 255])
|
18 |
|
19 |
+
# Make predictions using the loaded model
|
20 |
+
predictions = tf_model.predict(input_image)
|
21 |
+
class_index = np.argmax(predictions, axis=1)[0]
|
22 |
+
predicted_class = class_labels[class_index]
|
23 |
|
24 |
+
return predicted_class
|
25 |
|
26 |
+
# Create a Gradio interface
|
27 |
+
input_image = gr.inputs.Image(shape=(224, 224, 3)) # Define the input image shape
|
28 |
+
output_label = gr.outputs.Label() # Define the output label
|
|
|
|
|
29 |
|
30 |
+
gr.Interface(fn=classify_image, inputs=input_image, outputs=output_label).launch()
|