|
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(path): |
|
image = path.reshape((224, 224, 3)) |
|
image = tf.keras.utils.img_to_array(image) |
|
image = np.expand_dims(image, axis=0) |
|
pred = model.predict(image, verbose=0) |
|
pred = pred[0] |
|
confidences = {classnames[i]: round(float(pred[i]), 2) for i in range(50)} |
|
return confidences |
|
|
|
|
|
gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(shape=(224, 224)), |
|
outputs=gr.Label(num_top_classes=5), |
|
examples=[ |
|
"Dalbergia oliveri.JPG", |
|
"Eucalyptus.JPG", |
|
"Khaya senegalensis.JPG", |
|
"Syzygium nervosum.JPG", |
|
] |
|
).launch() |
|
|