File size: 751 Bytes
fe282ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Cargar modelo desde Hugging Face
model = tf.keras.models.load_model("https://huggingface.co/shaktibiplab/Animal-Classification/resolve/main/animal_model.h5")

labels = ["cat", "dog", "elephant", "horse", "lion", "tiger"]

def predict(image):
    image = image.resize((256, 256))
    img_array = np.array(image) / 255.0
    img_array = img_array.reshape(1, 256, 256, 3)
    prediction = model.predict(img_array)[0]
    index = np.argmax(prediction)
    label = labels[index]
    confidence = float(prediction[index])
    return f"{label} ({round(confidence * 100, 2)}%)"

iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="text")
iface.launch()