Uploaded app.py and requirements
Browse filesFor classifying into three classes
- app.py +38 -7
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,38 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing import image
|
5 |
+
|
6 |
+
# Load your trained model
|
7 |
+
model = load_model('my_modelled.h5')
|
8 |
+
|
9 |
+
# Define the class labels
|
10 |
+
class_labels = ['DR', 'DME', 'NONE']
|
11 |
+
|
12 |
+
def classify_image(img):
|
13 |
+
# Preprocess the image for the model
|
14 |
+
img = img.resize((256, 256)) # Resize image to match model input
|
15 |
+
img_array = image.img_to_array(img)
|
16 |
+
img_array = np.expand_dims(img_array, axis=0)
|
17 |
+
img_array = img_array / 255.0 # Normalize the image
|
18 |
+
|
19 |
+
# Predict the class
|
20 |
+
prediction = model.predict(img_array)
|
21 |
+
class_index = np.argmax(prediction)
|
22 |
+
class_label = class_labels[class_index]
|
23 |
+
|
24 |
+
return class_label
|
25 |
+
|
26 |
+
def create_interface():
|
27 |
+
# Define the Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=classify_image,
|
30 |
+
inputs=gr.inputs.Image(shape=(256, 256)),
|
31 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
32 |
+
live=True
|
33 |
+
)
|
34 |
+
return iface
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
interface = create_interface()
|
38 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
gradio
|