Horus7 commited on
Commit
b1325b9
·
verified ·
1 Parent(s): 1ee13ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -24
app.py CHANGED
@@ -1,24 +1,23 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
4
- import os
5
- import tensorflow as tf
6
- import numpy as np
7
  from keras.models import load_model
8
- from tensorflow.keras.utils import load_img
9
 
10
  # Charger le modèle
11
-
12
  model = load_model('best_model.h5')
13
 
14
-
15
  def format_decimal(value):
16
  decimal_value = format(value, ".2f")
17
  return decimal_value
18
-
19
  def detect(img):
 
 
 
20
  img = np.expand_dims(img, axis=0)
21
- img = img/255
 
22
  # Faire une prédiction
23
  prediction = model.predict(img)[0]
24
 
@@ -39,22 +38,11 @@ def detect(img):
39
 
40
  return texte
41
 
42
-
43
-
44
- # result = detect(img)
45
- # print(result)
46
- # os.system("tar -zxvf examples.tar.gz")
47
- # examples = ['examples/n1.jpeg', 'examples/n2.jpeg', 'examples/n3.jpeg', 'examples/n4.jpeg', 'examples/n5.jpeg',
48
- # 'examples/n6.jpeg', 'examples/n7.jpeg', 'examples/n8.jpeg', 'examples/p6.jpeg', 'examples/p7.jpeg',]
49
-
50
- input = gr.inputs.Image(shape=(100,100))
51
-
52
-
53
-
54
  title = "Orisha"
55
 
56
- iface = gr.Interface(fn=detect, inputs=input, outputs=[gr.Textbox(label="Classe", lines=10)],
57
- #examples = examples,
58
- #examples_per_page=20,
59
  title=title)
60
- iface.launch(inline=False)
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
 
 
 
4
  from keras.models import load_model
5
+ from tensorflow.keras.utils import load_img, img_to_array
6
 
7
  # Charger le modèle
 
8
  model = load_model('best_model.h5')
9
 
 
10
  def format_decimal(value):
11
  decimal_value = format(value, ".2f")
12
  return decimal_value
13
+
14
  def detect(img):
15
+ # Prétraiter l'image
16
+ img = img.resize((256, 256)) # Redimensionner l'image
17
+ img = img_to_array(img)
18
  img = np.expand_dims(img, axis=0)
19
+ img = img / 255.0 # Normaliser les valeurs de l'image
20
+
21
  # Faire une prédiction
22
  prediction = model.predict(img)[0]
23
 
 
38
 
39
  return texte
40
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  title = "Orisha"
42
 
43
+ iface = gr.Interface(fn=detect,
44
+ inputs=gr.Image(type="pil", shape=(256, 256)),
45
+ outputs=gr.Textbox(label="Classe", lines=10),
46
  title=title)
47
+
48
+ iface.launch(inline=False)