Spaces:
Runtime error
Runtime error
Commit
•
791c3a9
1
Parent(s):
6504c6d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
import gradio as gr
|
3 |
+
import tensorflow as tf
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Cargar el modelo .h5
|
8 |
+
model = tf.keras.models.load_model('sports.h5')
|
9 |
+
|
10 |
+
# Definir las clases
|
11 |
+
classes = ['americano', 'ciclismo', 'golf', 'futbol', 'tenis', 'basket', 'natacion', 'boxeo', 'beisball', 'f1']
|
12 |
+
|
13 |
+
# Función de predicción
|
14 |
+
def predict(image):
|
15 |
+
image = Image.fromarray(image).resize((224, 224))
|
16 |
+
image = np.array(image) / 255.0
|
17 |
+
image = np.expand_dims(image, axis=0)
|
18 |
+
predictions = model.predict(image)
|
19 |
+
predicted_class = classes[np.argmax(predictions)]
|
20 |
+
return predicted_class
|
21 |
+
|
22 |
+
# Interfaz de Gradio
|
23 |
+
interface = gr.Interface(fn=predict, inputs=gr.inputs.Image(type="numpy"), outputs="text")
|
24 |
+
|
25 |
+
# Ejecutar la interfaz
|
26 |
+
if __name__ == "__main__":
|
27 |
+
interface.launch()
|