sweetfelinity commited on
Commit
bc70419
·
verified ·
1 Parent(s): 8ab32da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -48
app.py CHANGED
@@ -1,49 +1,50 @@
1
- import tensorflow as tf
2
- import gradio as gr
3
- import numpy as np
4
- import cv2
5
- import os
6
-
7
- classes = ["Abyssinian", "Bengal", "Birman", "Bombay", "British Shorthair", "Egyptian Mau", "Maine Coon", "Persian", "Ragdoll", "Russian Blue", "Siamese", "Sphynx"]
8
- example_images = ["examples/" + f for f in os.listdir("examples")]
9
-
10
- img_size = 400
11
- model = tf.keras.models.load_model("CatClassifier.keras")
12
-
13
- def model_predict(image):
14
- image = cv2.resize(image, (img_size, img_size))
15
- image = np.expand_dims(image, axis=0)
16
-
17
- predictions = model.predict(image)
18
- predictions = predictions[0]
19
-
20
- predicted_class_index = np.argmax(predictions)
21
- predicted_class = classes[predicted_class_index]
22
- pred_dict = {}
23
-
24
- for i in range(len(classes)):
25
- pred_dict[classes[i]] = predictions[i]
26
-
27
- return predicted_class, pred_dict
28
-
29
-
30
- def predict_breed(image):
31
- if image is None:
32
- return "Please attach an image first!", None
33
-
34
- return model_predict(image)
35
-
36
- with gr.Blocks() as demo:
37
- with gr.Row():
38
- with gr.Column():
39
- image_input = gr.Image(label="Cat Image")
40
- run_button = gr.Button(variant="primary")
41
- examples = gr.Examples(example_images,inputs=image_input)
42
- with gr.Column():
43
- breed_output = gr.Text(label="Predicted Breed", interactive=False)
44
- predict_labels = gr.Label(label="Class Probabilties")
45
-
46
- run_button.click(fn=predict_breed, inputs=image_input, outputs=[breed_output, predict_labels])
47
-
48
- if __name__ == "__main__":
 
49
  demo.launch()
 
1
+ import tensorflow as tf
2
+ from tensorflow import keras
3
+ import gradio as gr
4
+ import numpy as np
5
+ import cv2
6
+ import os
7
+
8
+ classes = ["Abyssinian", "Bengal", "Birman", "Bombay", "British Shorthair", "Egyptian Mau", "Maine Coon", "Persian", "Ragdoll", "Russian Blue", "Siamese", "Sphynx"]
9
+ example_images = ["examples/" + f for f in os.listdir("examples")]
10
+
11
+ img_size = 400
12
+ model = tf.keras.models.load_model("CatClassifier.keras")
13
+
14
+ def model_predict(image):
15
+ image = cv2.resize(image, (img_size, img_size))
16
+ image = np.expand_dims(image, axis=0)
17
+
18
+ predictions = model.predict(image)
19
+ predictions = predictions[0]
20
+
21
+ predicted_class_index = np.argmax(predictions)
22
+ predicted_class = classes[predicted_class_index]
23
+ pred_dict = {}
24
+
25
+ for i in range(len(classes)):
26
+ pred_dict[classes[i]] = predictions[i]
27
+
28
+ return predicted_class, pred_dict
29
+
30
+
31
+ def predict_breed(image):
32
+ if image is None:
33
+ return "Please attach an image first!", None
34
+
35
+ return model_predict(image)
36
+
37
+ with gr.Blocks() as demo:
38
+ with gr.Row():
39
+ with gr.Column():
40
+ image_input = gr.Image(label="Cat Image")
41
+ run_button = gr.Button(variant="primary")
42
+ examples = gr.Examples(example_images,inputs=image_input)
43
+ with gr.Column():
44
+ breed_output = gr.Text(label="Predicted Breed", interactive=False)
45
+ predict_labels = gr.Label(label="Class Probabilties")
46
+
47
+ run_button.click(fn=predict_breed, inputs=image_input, outputs=[breed_output, predict_labels])
48
+
49
+ if __name__ == "__main__":
50
  demo.launch()