Spaces:
Sleeping
Sleeping
altrastorique
commited on
Commit
•
cab254d
1
Parent(s):
0efa173
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
3 |
from tensorflow.keras.models import load_model
|
4 |
import pandas as pd
|
5 |
import numpy as np
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
def display_image_and_prediction(
|
11 |
model = load_model('mon_modele/mon_modele')
|
12 |
generator = np.load('test_data.npy')
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
img_array = np.expand_dims(Oiseau_resized, axis=0)
|
19 |
-
img_array = img_array.astype('float32') / 255.0
|
20 |
-
|
21 |
-
prediction = model.predict(img_array)
|
22 |
predicted_class = np.argmax(prediction)
|
23 |
predicted_class_name = generator[predicted_class]
|
|
|
24 |
scientificName = dataCsv.loc[dataCsv["labels"]==predicted_class_name,"scientific name"].iloc[0]#récupération du nom scientifique de cette oiseau
|
25 |
-
|
26 |
-
return
|
27 |
-
|
28 |
iface = gr.Interface(fn=display_image_and_prediction, inputs="image", outputs=["text","text"])
|
29 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from tensorflow.keras.models import load_model
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
5 |
+
import cv2
|
6 |
+
|
7 |
+
dataCsv = pd.read_csv('birds.csv')
|
8 |
+
|
9 |
+
def display_image_and_prediction(bird):
|
10 |
model = load_model('mon_modele/mon_modele')
|
11 |
generator = np.load('test_data.npy')
|
12 |
+
|
13 |
+
bird_array_resized = cv2.resize(bird,(224, 224), 3)
|
14 |
+
bird_array = np.expand_dims(bird_array_resized.astype('float32') / 255.0, axis=0)
|
15 |
+
prediction = model.predict(bird_array)
|
16 |
+
|
|
|
|
|
|
|
|
|
17 |
predicted_class = np.argmax(prediction)
|
18 |
predicted_class_name = generator[predicted_class]
|
19 |
+
|
20 |
scientificName = dataCsv.loc[dataCsv["labels"]==predicted_class_name,"scientific name"].iloc[0]#récupération du nom scientifique de cette oiseau
|
21 |
+
|
22 |
+
return predicted_class_name, scientificName
|
23 |
+
|
24 |
iface = gr.Interface(fn=display_image_and_prediction, inputs="image", outputs=["text","text"])
|
25 |
+
iface.launch(share=True)
|