oleksiikondus commited on
Commit
c31dcff
·
1 Parent(s): b1669c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -6,7 +6,12 @@ from tensorflow import keras
6
 
7
  model = keras.models.load_model('model_CNN.h5')
8
 
9
- # Створення функції для передбачення символу
 
 
 
 
 
10
  def predict_image(image):
11
  image = cv2.resize(image, (224, 224))
12
  image = np.asarray(image)
@@ -14,7 +19,8 @@ def predict_image(image):
14
  predictions = model.predict(np.expand_dims(image, axis=0))[0]
15
  prediction = {}
16
  for index, probability in enumerate(predictions) :
17
- prediction[class_names[index]] = float(round(probability, 3))
 
18
  return prediction
19
 
20
  demo = gr.Blocks()
@@ -22,9 +28,9 @@ demo = gr.Blocks()
22
  with demo:
23
  gr.Markdown("Predicte image (dog or cat)")
24
  with gr.Tab("Predict image"):
25
- image_input = gr.Image(label="Upload image")
26
- output = gr.Label(label="A letter predicted by a neural network")
27
- image_button = gr.Button("Predict")
28
- image_button.click(predict_image, inputs=image_input, outputs=output)
29
 
30
- demo.launch()
 
6
 
7
  model = keras.models.load_model('model_CNN.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)
 
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()
 
28
  with demo:
29
  gr.Markdown("Predicte image (dog or cat)")
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()