Spaces:
Configuration error
Configuration error
Upload 2 files
Browse files- app.py +52 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import chess
|
| 3 |
+
import chess.pgn
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import numpy as np
|
| 6 |
+
import io
|
| 7 |
+
import base64
|
| 8 |
+
from io import BytesIO
|
| 9 |
+
|
| 10 |
+
# (Aquí va toda la clase AnalizadorAjedrez que te pasé antes)
|
| 11 |
+
|
| 12 |
+
def analizar_y_mostrar(pgn_text):
|
| 13 |
+
"""Función que Gradio usará para la interfaz"""
|
| 14 |
+
try:
|
| 15 |
+
analizador = AnalizadorAjedrez()
|
| 16 |
+
blancas, negras, resultado = analizador.analizar_partida(pgn_text)
|
| 17 |
+
|
| 18 |
+
# Generar gráficos y convertirlos a base64 para mostrar en Gradio
|
| 19 |
+
fig = analizador.generar_graficos_gradio(blancas, negras)
|
| 20 |
+
|
| 21 |
+
# Convertir figura a imagen para Gradio
|
| 22 |
+
buf = BytesIO()
|
| 23 |
+
fig.savefig(buf, format='png', dpi=100, bbox_inches='tight')
|
| 24 |
+
buf.seek(0)
|
| 25 |
+
plt.close(fig)
|
| 26 |
+
|
| 27 |
+
# Generar reporte textual
|
| 28 |
+
reporte = analizador.generar_reporte_textual()
|
| 29 |
+
|
| 30 |
+
return buf, reporte
|
| 31 |
+
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return None, f"❌ Error: {str(e)}"
|
| 34 |
+
|
| 35 |
+
# Interfaz de Gradio
|
| 36 |
+
demo = gr.Interface(
|
| 37 |
+
fn=analizar_y_mostrar,
|
| 38 |
+
inputs=gr.Textbox(
|
| 39 |
+
label="Pega tu partida PGN aquí",
|
| 40 |
+
lines=10,
|
| 41 |
+
placeholder="[Event 'Mi Partida']\n[White 'Yo']\n[Black 'Rival']\n\n1. e4 e5 2. Nf3 Nc6 ..."
|
| 42 |
+
),
|
| 43 |
+
outputs=[
|
| 44 |
+
gr.Image(label="Análisis Gráfico de la Partida"),
|
| 45 |
+
gr.Textbox(label="Reporte de Análisis")
|
| 46 |
+
],
|
| 47 |
+
title="♟️ Analizador de Partidas de Ajedrez",
|
| 48 |
+
description="Pega cualquier partida en formato PGN y obtén un análisis completo con gráficos y estadísticas."
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chess
|
| 2 |
+
matplotlib
|
| 3 |
+
numpy
|
| 4 |
+
seaborn
|
| 5 |
+
gradio
|