EspacioDeporte / app.py
DarioCalixto's picture
Create app.py
791c3a9 verified
raw
history blame
No virus
786 Bytes
# 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()