Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Cargar modelo desde Hugging Face
|
7 |
+
model = tf.keras.models.load_model("https://huggingface.co/shaktibiplab/Animal-Classification/resolve/main/animal_model.h5")
|
8 |
+
|
9 |
+
labels = ["cat", "dog", "elephant", "horse", "lion", "tiger"]
|
10 |
+
|
11 |
+
def predict(image):
|
12 |
+
image = image.resize((256, 256))
|
13 |
+
img_array = np.array(image) / 255.0
|
14 |
+
img_array = img_array.reshape(1, 256, 256, 3)
|
15 |
+
prediction = model.predict(img_array)[0]
|
16 |
+
index = np.argmax(prediction)
|
17 |
+
label = labels[index]
|
18 |
+
confidence = float(prediction[index])
|
19 |
+
return f"{label} ({round(confidence * 100, 2)}%)"
|
20 |
+
|
21 |
+
iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="text")
|
22 |
+
iface.launch()
|