import gradio as gr import tensorflow as tf import pandas as pd import numpy as np import cv2 # Load the trained model model = tf.keras.models.load_model("model.h5") # Load the bird labels bird_labels = pd.read_csv("birds.csv") def classify_image(input_image): # Preprocess the input image img = cv2.resize(input_image, (224, 224)) img_array = img / 255.0 img_array = img_array.reshape(1, 224, 224, 3) # Make predictions prediction = model.predict(img_array) # Get the index of the maximum prediction max_index = np.argmax(prediction[0]) # Get the bird's name and scientific name bird_name = bird_labels.loc[max_index, "labels"] scientific_name = bird_labels.loc[max_index, "scientific name"] return bird_name, scientific_name # Define the Gradio interface image_input = gr.inputs.Image(shape=(224, 224)) outputs = [ gr.outputs.Label(label="Bird Name"), gr.outputs.Label(label="Scientific Name") ] iface = gr.Interface( classify_image, inputs=image_input, outputs=outputs, title="Bird Image Classifier", description="Upload an image of a bird, and this classifier will predict the bird's name and its scientific name.", examples=[ # Add paths to example images here ], allow_flagging=False ) # Launch the Gradio app on Hugging Face Spaces iface.launch()