File size: 868 Bytes
a432113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28


import gradio as gr
from datasets import load_dataset
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
from tensorflow.keras.models import load_model
from keras.preprocessing import image

model3 = load_model('best_beans.h5')

leaf_class=['angular_leaf_spot', 'bean_rust', 'healthy']

def classify_image(img):
  img_width, img_height = 224, 224
  img = image.load_img(img, target_size = (img_width, img_height))
  img = image.img_to_array(img)
  img = np.expand_dims(img, axis = 0)
  prediction = model3.predict(img)[0]
  return {leaf_class[i]: float(prediction[i]) for i in range(3)}

gr.Interface(fn=classify_image,
             inputs=gr.Image( type ="filepath"),
             outputs=gr.Label(num_top_classes=1)).launch(debug=True)