File size: 1,360 Bytes
d03ec30
 
 
 
61a2c5c
d03ec30
 
 
 
 
 
 
 
 
61a2c5c
 
d03ec30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e360cb8
 
d03ec30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()