import pickle import pandas as pd import gradio as gr import sklearn # Cargar el modelo with open('modelo_search.pkl', 'rb') as f: model = pickle.load(f) def predict(mainline_moves, Opening, WhiteFideId, BlackFideId, WhiteElo, BlackElo): df_model = pd.DataFrame({"mainline_moves":mainline_moves, "Opening":Opening, "WhiteFideId":WhiteFideId, "BlackFideId":BlackFideId, "WhiteElo": WhiteElo, "BlackElo": BlackElo}, index= [0]) label_pred = model.predict(df_model)[0].item() if label_pred == 0: return "Ganó Blancas" elif label_pred == 1: return "Ganó Negras" else: return "Tablas" # Definir los widgets de entrada mainline_moves = gr.inputs.Number(label="Mainline Moves") Opening = gr.inputs.Textbox(label="Opening") WhiteFideId = gr.inputs.Textbox(label="White Fide ID") BlackFideId = gr.inputs.Textbox(label="Black Fide ID") WhiteElo = gr.inputs.Slider(label="White Elo", minimum=0, maximum=3000, step=10, default=2400) BlackElo = gr.inputs.Slider(label="Black Elo", minimum=0, maximum=3000, step=10, default=2400) # Definir la salida output_label = gr.outputs.Label(num_top_classes=1, label="Resultado de la partida") # Definir la interfaz iface = gr.Interface(fn=predict, inputs=[mainline_moves, Opening, WhiteFideId, BlackFideId, WhiteElo, BlackElo], outputs=output_label, title="Predicción de partidas de Ajedrez", theme=gr.themes.Soft(), layout="horizontal", allow_flagging=False, description="Coloca los datos solicitados y descubre el resultado de la partida!") # Ejecutar la interfaz iface.launch()