import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load the trained model load_model = tf.keras.models.load_model('checkpoint_model.h5') # replace with actual model path # Assuming 'label_names' is a list of class names label_names = ['asoka', 'kecubung', 'krokot', 'periwinkle', 'telang', 'zinnia'] # replace with actual class names # Image size to match the input size of your model IMG_SIZE = (224, 224) # replace with your actual image size def predict_image(image): img = Image.fromarray(image) img = img.resize(IMG_SIZE) x = tf.keras.preprocessing.image.img_to_array(img) x = np.expand_dims(x, axis=0) classes = load_model.predict(x, batch_size=10) outclass = np.argmax(classes) return label_names[outclass], {label: float(classes[0][i]) for i, label in enumerate(label_names)} def classify_image(image): image = np.array(image) outclass, classes = predict_image(image) return outclass, classes css = """ body { background-color: #D9FO8absF; } """ with gr.Blocks(css=css) as demo: gr.Markdown('

Bunga Herbal App
') gr.Markdown('Tipe Bunga
') # Optional: Display a placeholder image gr.Image("/content/drive/MyDrive/bismillah.png") with gr.Row(): with gr.Column(): image_input = gr.Image(type="pil", label="Upload an image...") with gr.Column(): label_output = gr.Label(label="Predicted Label") confidence_output = gr.JSON(label="Prediction Confidence") # Inform the user about capturing an image gr.Markdown("**To capture an image using your phone's camera:**", label="**OR**") gr.Markdown( "1. Open your device's camera app." "2. Take a picture of the flower you want to identify." "3. Save the image." "4. Upload the saved image here using the upload button above." ) image_input.change(fn=classify_image, inputs=image_input, outputs=[label_output, confidence_output]) demo.launch()