SuperSecureHuman/Tree-API
0
1import gradio as gr2#from transformers import pipeline3from tensorflow.keras.models import load_model4 5#pipe = pipeline(task="image-classification", model="SuperSecureHuman/Flower-CNN")6 7model = load_model('./model.h5')8 9 10def predict_image(img):11 img_4d = img.reshape(-1, 224, 224, 3)12 prediction = model.predict(img_4d)[0]13 return {class_names[i]: float(prediction[i]) for i in range(10)}14 15 16class_names = ['Crescentia_Cujete', 'Fiddle_Wood', 'Gold_Apple', 'Hill_Mango', 'Indian_Tulip_Tree', 'Mahagony', 'Pala_Indigo_Plant', 'Spanish_Cherry', 'Teak', 'Yellow_Trumpet']17 18image = gr.inputs.Image(shape=(224, 224))19 20label = gr.outputs.Label(num_top_classes=10)21 22gr.Interface(fn=predict_image,23 title="Tree Classification",24 description="Tree CNN",25 inputs=image,26 outputs=label,27 live=True,28 interpretation='default',29 allow_flagging="never").launch()30 