Spaces:
Runtime error
Runtime error
| 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() |