Commit
·
636f7ab
1
Parent(s):
0fc613b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import tensorflow as tf
|
3 |
+
import cv2
|
4 |
+
import gradio as gr
|
5 |
+
from tensorflow import keras
|
6 |
+
|
7 |
+
model = keras.models.load_model('model_InceptionV3.h5')
|
8 |
+
|
9 |
+
class_mapping = {1: 'Собака', 2: 'Кінь', 3: 'Слон', 4:'Метелик',
|
10 |
+
5: 'Курка', 6: 'Кіт', 7:'Корова', 8: 'Вівця',
|
11 |
+
9: 'Павук', 10: 'Білка'
|
12 |
+
}
|
13 |
+
|
14 |
+
# Створення функції для передбачення тварини
|
15 |
+
def predict_image(image):
|
16 |
+
image = cv2.resize(image, (224, 224))
|
17 |
+
image = np.asarray(image)
|
18 |
+
image = image.astype('float32') / 255.0
|
19 |
+
predictions = model.predict(np.expand_dims(image, axis=0))[0]
|
20 |
+
prediction = {}
|
21 |
+
for index, probability in enumerate(predictions) :
|
22 |
+
prediction[class_mapping[index+1]] = float(round(probability, 3))
|
23 |
+
print(prediction)
|
24 |
+
return prediction
|
25 |
+
|
26 |
+
demo = gr.Blocks()
|
27 |
+
# Створення інтерфейсу Gradio
|
28 |
+
with demo:
|
29 |
+
gr.Markdown("What animal is in the picture")
|
30 |
+
with gr.Tab("Predict image"):
|
31 |
+
image_input = gr.Image(label="Upload image")
|
32 |
+
output = gr.Label(label="Animal predicted by neural network")
|
33 |
+
image_button = gr.Button("Predict")
|
34 |
+
image_button.click(predict_image, inputs=image_input, outputs=output)
|
35 |
+
|
36 |
+
demo.launch()
|