Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,11 @@ import numpy as np
|
|
5 |
import cv2
|
6 |
|
7 |
# Load the trained model
|
8 |
-
model_path = '
|
9 |
model = load_model(model_path)
|
10 |
|
|
|
|
|
11 |
# Define a function to preprocess the input image
|
12 |
def preprocess_image(img):
|
13 |
# Check if img is a file path or an image object
|
@@ -38,7 +40,10 @@ def classify_image(img):
|
|
38 |
# Get the predicted class label
|
39 |
predicted_class = np.argmax(predictions)
|
40 |
|
41 |
-
|
|
|
|
|
|
|
42 |
|
43 |
# Create a Gradio interface
|
44 |
iface = gr.Interface(fn=classify_image,
|
@@ -47,11 +52,4 @@ iface = gr.Interface(fn=classify_image,
|
|
47 |
live=True)
|
48 |
|
49 |
# Launch the Gradio app
|
50 |
-
iface.launch()
|
51 |
-
|
52 |
-
|
53 |
-
# In[ ]:
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
5 |
import cv2
|
6 |
|
7 |
# Load the trained model
|
8 |
+
model_path = 'C:/Users/kamel/Documents/Image Classification/model_checkpoint_manual_effnet.h5'
|
9 |
model = load_model(model_path)
|
10 |
|
11 |
+
class_names = ['ADONIS', 'AFRICAN GIANT SWALLOWTAIL', 'AMERICAN SNOOT', 'AN 88', 'APPOLLO', 'ARCIGERA FLOWER MOTH', 'ATALA', 'ATLAS MOTH', 'BANDED ORANGE HELICONIAN', 'BANDED PEACOCK']
|
12 |
+
|
13 |
# Define a function to preprocess the input image
|
14 |
def preprocess_image(img):
|
15 |
# Check if img is a file path or an image object
|
|
|
40 |
# Get the predicted class label
|
41 |
predicted_class = np.argmax(predictions)
|
42 |
|
43 |
+
# Get the predicted class name
|
44 |
+
predicted_class_name = class_names[predicted_class]
|
45 |
+
|
46 |
+
return f"Predicted Class: {predicted_class_name}"
|
47 |
|
48 |
# Create a Gradio interface
|
49 |
iface = gr.Interface(fn=classify_image,
|
|
|
52 |
live=True)
|
53 |
|
54 |
# Launch the Gradio app
|
55 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|