|
import tensorflow as tf |
|
from tensorflow import keras |
|
import numpy as np |
|
import gradio as gr |
|
|
|
model = keras.models.load_model("Model.keras") |
|
|
|
classnames = [ |
|
"Acacia", |
|
"Adenanthera microsperma", |
|
"Adenium species", |
|
"Anacardium occidentale", |
|
"Annona squamosa", |
|
"Artocarpus altilis", |
|
"Artocarpus heterophyllus", |
|
"Barringtonia acutangula", |
|
"Cananga odorata", |
|
"Carica papaya", |
|
"Casuarina equisetifolia", |
|
"Cedrus", |
|
"Chrysophyllum cainino", |
|
"Citrus aurantiifolia", |
|
"Citrus grandis", |
|
"Cocos nucifera", |
|
"Dalbergia oliveri", |
|
"Delonix regia", |
|
"Dipterocarpus alatus", |
|
"Erythrina fusca", |
|
"Eucalyptus", |
|
"Ficus microcarpa", |
|
"Ficus racemosa", |
|
"Gmelina arborea Roxb", |
|
"Hevea brasiliensis", |
|
"Hopea", |
|
"Khaya senegalensis", |
|
"Khaya senegalensis A.Juss", |
|
"Lagerstroemia speciosa", |
|
"Magnolia alba", |
|
"Mangifera", |
|
"Melaleuca", |
|
"Melia azedarach", |
|
"Musa", |
|
"Nephelium lappaceum", |
|
"Persea", |
|
"Polyalthia longifolia", |
|
"Prunnus", |
|
"Prunus salicina", |
|
"Psidium guajava", |
|
"Pterocarpus macrocarpus", |
|
"Senna siamea", |
|
"Spondias mombin L", |
|
"Syzygium nervosum", |
|
"Tamarindus indica", |
|
"Tectona grandis", |
|
"Terminalia catappa", |
|
"Veitchia merrilli", |
|
"Wrightia", |
|
"Wrightia religiosa", |
|
] |
|
|
|
|
|
def predict(image): |
|
img = tf.image.resize(image, (224, 224)) |
|
|
|
img = tf.cast(img, tf.float32) / 255.0 |
|
|
|
pred = model.predict(tf.expand_dims(img, axis=0)) |
|
|
|
confidences = {classnames[i]: float(pred[0][i]) for i in range(len(classnames))} |
|
return confidences |
|
|
|
|
|
gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(), |
|
outputs=gr.Label(num_top_classes=5), |
|
examples=[ |
|
"Dalbergia oliveri.JPG", |
|
"Eucalyptus.JPG", |
|
"Khaya senegalensis.JPG", |
|
"Syzygium nervosum.JPG", |
|
], |
|
).launch() |
|
|