CoolFace
Apppublic

kornpp/Beans

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py28 linesDownload Raw Back to root
1 2 3import gradio as gr4from PIL import Image5import matplotlib.pyplot as plt6import numpy as np7import tensorflow as tf8from tensorflow.keras import layers9from tensorflow.keras.models import Sequential10from tensorflow.keras.models import load_model11from keras.preprocessing import image12 13model3 = load_model('best_beans.h5')14 15leaf_class=['angular_leaf_spot', 'bean_rust', 'healthy']16 17 18def classify_image(img):19  img_width, img_height = 224, 22420  img = image.load_img(img, target_size = (img_width, img_height))21  img = image.img_to_array(img)22  img = np.expand_dims(img, axis = 0)23  prediction = model3.predict(img)[0]24  return {leaf_class[i]: float(prediction[i]) for i in range(3)}25 26gr.Interface(fn=classify_image,27             inputs=gr.Image( type ="filepath"),28             outputs=gr.Label(num_top_classes=1)).launch(debug=True)