File size: 786 Bytes
791c3a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Cargar el modelo .h5
model = tf.keras.models.load_model('sports.h5')

# Definir las clases
classes = ['americano', 'ciclismo', 'golf', 'futbol', 'tenis', 'basket', 'natacion', 'boxeo', 'beisball', 'f1']

# Función de predicción
def predict(image):
    image = Image.fromarray(image).resize((224, 224))
    image = np.array(image) / 255.0
    image = np.expand_dims(image, axis=0)
    predictions = model.predict(image)
    predicted_class = classes[np.argmax(predictions)]
    return predicted_class

# Interfaz de Gradio
interface = gr.Interface(fn=predict, inputs=gr.inputs.Image(type="numpy"), outputs="text")

# Ejecutar la interfaz
if __name__ == "__main__":
    interface.launch()