Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
from tensorflow import keras
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
model = keras.models.load_model("Model.keras")
|
| 7 |
+
|
| 8 |
+
classnames = [
|
| 9 |
+
"Acacia",
|
| 10 |
+
"Adenanthera microsperma",
|
| 11 |
+
"Adenium species",
|
| 12 |
+
"Anacardium occidentale",
|
| 13 |
+
"Annona squamosa",
|
| 14 |
+
"Artocarpus altilis",
|
| 15 |
+
"Artocarpus heterophyllus",
|
| 16 |
+
"Barringtonia acutangula",
|
| 17 |
+
"Cananga odorata",
|
| 18 |
+
"Carica papaya",
|
| 19 |
+
"Casuarina equisetifolia",
|
| 20 |
+
"Cedrus",
|
| 21 |
+
"Chrysophyllum cainino",
|
| 22 |
+
"Citrus aurantiifolia",
|
| 23 |
+
"Citrus grandis",
|
| 24 |
+
"Cocos nucifera",
|
| 25 |
+
"Dalbergia oliveri",
|
| 26 |
+
"Delonix regia",
|
| 27 |
+
"Dipterocarpus alatus",
|
| 28 |
+
"Erythrina fusca",
|
| 29 |
+
"Eucalyptus",
|
| 30 |
+
"Ficus microcarpa",
|
| 31 |
+
"Ficus racemosa",
|
| 32 |
+
"Gmelina arborea Roxb",
|
| 33 |
+
"Hevea brasiliensis",
|
| 34 |
+
"Hopea",
|
| 35 |
+
"Khaya senegalensis",
|
| 36 |
+
"Khaya senegalensis A.Juss",
|
| 37 |
+
"Lagerstroemia speciosa",
|
| 38 |
+
"Magnolia alba",
|
| 39 |
+
"Mangifera",
|
| 40 |
+
"Melaleuca",
|
| 41 |
+
"Melia azedarach",
|
| 42 |
+
"Musa",
|
| 43 |
+
"Nephelium lappaceum",
|
| 44 |
+
"Persea",
|
| 45 |
+
"Polyalthia longifolia",
|
| 46 |
+
"Prunnus",
|
| 47 |
+
"Prunus salicina",
|
| 48 |
+
"Psidium guajava",
|
| 49 |
+
"Pterocarpus macrocarpus",
|
| 50 |
+
"Senna siamea",
|
| 51 |
+
"Spondias mombin L",
|
| 52 |
+
"Syzygium nervosum",
|
| 53 |
+
"Tamarindus indica",
|
| 54 |
+
"Tectona grandis",
|
| 55 |
+
"Terminalia catappa",
|
| 56 |
+
"Veitchia merrilli",
|
| 57 |
+
"Wrightia",
|
| 58 |
+
"Wrightia religiosa",
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def predict(path):
|
| 63 |
+
image = path.reshape((224, 224, 3))
|
| 64 |
+
image = tf.keras.utils.img_to_array(image)
|
| 65 |
+
image = np.expand_dims(image, axis=0)
|
| 66 |
+
pred = model.predict(image, verbose=0)
|
| 67 |
+
pred = pred[0]
|
| 68 |
+
confidences = {classnames[i]: round(float(pred[i]), 2) for i in range(50)}
|
| 69 |
+
return confidences
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
gr.Interface(
|
| 73 |
+
fn=predict,
|
| 74 |
+
inputs=gr.Image(shape=(224, 224)),
|
| 75 |
+
outputs=gr.Label(num_top_classes=5),
|
| 76 |
+
examples=[
|
| 77 |
+
"Dalbergia oliveri.JPG",
|
| 78 |
+
"Eucalyptus.JPG",
|
| 79 |
+
"Khaya senegalensis.JPG",
|
| 80 |
+
"Syzygium nervosum.JPG",
|
| 81 |
+
|
| 82 |
+
],
|
| 83 |
+
).launch()
|