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6 |
+
"id": "58a44d93-676f-4b67-a2a0-af39673f1680",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"scrolled": true
|
| 9 |
+
},
|
| 10 |
+
"outputs": [
|
| 11 |
+
{
|
| 12 |
+
"name": "stdout",
|
| 13 |
+
"output_type": "stream",
|
| 14 |
+
"text": [
|
| 15 |
+
"* Running on local URL: http://127.0.0.1:7860\n",
|
| 16 |
+
"\n",
|
| 17 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 18 |
+
]
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"data": {
|
| 22 |
+
"text/html": [
|
| 23 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 24 |
+
],
|
| 25 |
+
"text/plain": [
|
| 26 |
+
"<IPython.core.display.HTML object>"
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
"metadata": {},
|
| 30 |
+
"output_type": "display_data"
|
| 31 |
+
}
|
| 32 |
+
],
|
| 33 |
+
"source": [
|
| 34 |
+
"import os\n",
|
| 35 |
+
"import pandas as pd\n",
|
| 36 |
+
"import pickle\n",
|
| 37 |
+
"import gradio as gr\n",
|
| 38 |
+
"import numpy as np\n",
|
| 39 |
+
"import pandas as pd\n",
|
| 40 |
+
"import base64\n",
|
| 41 |
+
"\n",
|
| 42 |
+
"# Carga modelo\n",
|
| 43 |
+
"with open(\"modelo_random_forest.pkl\", \"rb\") as file:\n",
|
| 44 |
+
" model = pickle.load(file)\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"# Carga datos\n",
|
| 47 |
+
"ruta_datos = \"datos_premier_consolidado.csv\"\n",
|
| 48 |
+
"df = pd.read_csv(ruta_datos, encoding=\"utf-8\", delimiter=\";\")\n",
|
| 49 |
+
"\n",
|
| 50 |
+
"RUTA_ESCUDOS = \"ESCUDOS\"\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"estadios = {\n",
|
| 53 |
+
" 'Arsenal': {'estadio': 'Emirates Stadium', 'capacidad': 60383},\n",
|
| 54 |
+
" 'Aston Villa': {'estadio': 'Villa Park', 'capacidad': 42824},\n",
|
| 55 |
+
" 'Birmingham': {'estadio': 'St Andrew\\'s', 'capacidad': 29409},\n",
|
| 56 |
+
" 'Blackburn': {'estadio': 'Ewood Park', 'capacidad': 31367},\n",
|
| 57 |
+
" 'Blackpool': {'estadio': 'Bloomfield Road', 'capacidad': 16750},\n",
|
| 58 |
+
" 'Bolton': {'estadio': 'University of Bolton Stadium', 'capacidad': 28723},\n",
|
| 59 |
+
" 'Bournemouth': {'estadio': 'Vitality Stadium', 'capacidad': 11307},\n",
|
| 60 |
+
" 'Brentford': {'estadio': 'Gtech Community Stadium', 'capacidad': 17250},\n",
|
| 61 |
+
" 'Brighton': {'estadio': 'American Express Community Stadium', 'capacidad': 31872},\n",
|
| 62 |
+
" 'Burnley': {'estadio': 'Turf Moor', 'capacidad': 22546},\n",
|
| 63 |
+
" 'Cardiff': {'estadio': 'Cardiff City Stadium', 'capacidad': 33280},\n",
|
| 64 |
+
" 'Charlton': {'estadio': 'The Valley', 'capacidad': 27111},\n",
|
| 65 |
+
" 'Chelsea': {'estadio': 'Stamford Bridge', 'capacidad': 41841},\n",
|
| 66 |
+
" 'Crystal Palace': {'estadio': 'Selhurst Park', 'capacidad': 26309},\n",
|
| 67 |
+
" 'Derby': {'estadio': 'Pride Park Stadium', 'capacidad': 33597},\n",
|
| 68 |
+
" 'Everton': {'estadio': 'Goodison Park', 'capacidad': 40569},\n",
|
| 69 |
+
" 'Fulham': {'estadio': 'Craven Cottage', 'capacidad': 25700},\n",
|
| 70 |
+
" 'Huddersfield': {'estadio': 'John Smith\\'s Stadium', 'capacidad': 24500},\n",
|
| 71 |
+
" 'Hull': {'estadio': 'MKM Stadium', 'capacidad': 25400},\n",
|
| 72 |
+
" 'Leeds': {'estadio': 'Elland Road', 'capacidad': 40204},\n",
|
| 73 |
+
" 'Leicester': {'estadio': 'King Power Stadium', 'capacidad': 34310},\n",
|
| 74 |
+
" 'Liverpool': {'estadio': 'Anfield', 'capacidad': 61276},\n",
|
| 75 |
+
" 'Luton': {'estadio': 'Kenilworth Road', 'capacidad': 10356},\n",
|
| 76 |
+
" 'Man City': {'estadio': 'Etihad Stadium', 'capacidad': 55097},\n",
|
| 77 |
+
" 'Man United': {'estadio': 'Old Trafford', 'capacidad': 76212},\n",
|
| 78 |
+
" 'Middlesbrough': {'estadio': 'Riverside Stadium', 'capacidad': 34988},\n",
|
| 79 |
+
" 'Newcastle': {'estadio': 'St. James\\' Park', 'capacidad': 52758},\n",
|
| 80 |
+
" 'Norwich': {'estadio': 'Carrow Road', 'capacidad': 27606},\n",
|
| 81 |
+
" \"Nott'm Forest\": {'estadio': 'The City Ground', 'capacidad': 30576},\n",
|
| 82 |
+
" 'Portsmouth': {'estadio': 'Fratton Park', 'capacidad': 20821},\n",
|
| 83 |
+
" 'QPR': {'estadio': 'Loftus Road', 'capacidad': 18360},\n",
|
| 84 |
+
" 'Reading': {'estadio': 'Select Car Leasing Stadium', 'capacidad': 24200},\n",
|
| 85 |
+
" 'Sheffield United': {'estadio': 'Bramall Lane', 'capacidad': 32702},\n",
|
| 86 |
+
" 'Southampton': {'estadio': 'St. Mary\\'s Stadium', 'capacidad': 32689},\n",
|
| 87 |
+
" 'Stoke': {'estadio': 'bet365 Stadium', 'capacidad': 30089},\n",
|
| 88 |
+
" 'Sunderland': {'estadio': 'Stadium of Light', 'capacidad': 49000},\n",
|
| 89 |
+
" 'Swansea': {'estadio': 'Swansea.com Stadium', 'capacidad': 21028},\n",
|
| 90 |
+
" 'Tottenham': {'estadio': 'Tottenham Hotspur Stadium', 'capacidad': 62850},\n",
|
| 91 |
+
" 'Watford': {'estadio': 'Vicarage Road', 'capacidad': 22200},\n",
|
| 92 |
+
" 'West Brom': {'estadio': 'The Hawthorns', 'capacidad': 28003},\n",
|
| 93 |
+
" 'West Ham': {'estadio': 'London Stadium', 'capacidad': 60000},\n",
|
| 94 |
+
" 'Wigan': {'estadio': 'DW Stadium', 'capacidad': 25138},\n",
|
| 95 |
+
" 'Wolves': {'estadio': 'Molineux Stadium', 'capacidad': 34674},\n",
|
| 96 |
+
" 'Coventry': {'estadio': 'Coventry Building Society Arena', 'capacidad': 32609},\n",
|
| 97 |
+
" 'Bradford': {'estadio': 'Valley Parade', 'capacidad': 25136}\n",
|
| 98 |
+
" # Añadir todos los demás estadios aquí\n",
|
| 99 |
+
"}\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"\n",
|
| 102 |
+
"\n",
|
| 103 |
+
"# Funciones auxiliares\n",
|
| 104 |
+
"def obtener_escudo(equipo):\n",
|
| 105 |
+
" ruta = os.path.join(RUTA_ESCUDOS, f\"{equipo}.png\")\n",
|
| 106 |
+
" if os.path.exists(ruta):\n",
|
| 107 |
+
" with open(ruta, \"rb\") as img_file:\n",
|
| 108 |
+
" img_base64 = base64.b64encode(img_file.read()).decode('utf-8')\n",
|
| 109 |
+
" return f\"<img src='data:image/png;base64,{img_base64}' width='80' height='80' style='margin:0px;'>\"\n",
|
| 110 |
+
" else:\n",
|
| 111 |
+
" return f\"<p style='color:red;'>Escudo no encontrado</p>\"\n",
|
| 112 |
+
"\n",
|
| 113 |
+
"def asignar_color_resultado(local, visitante):\n",
|
| 114 |
+
" if local > visitante:\n",
|
| 115 |
+
" return \"green\"\n",
|
| 116 |
+
" elif local < visitante:\n",
|
| 117 |
+
" return \"red\"\n",
|
| 118 |
+
" else:\n",
|
| 119 |
+
" return \"blue\"\n",
|
| 120 |
+
"\n",
|
| 121 |
+
"# Tu función corregida y definitiva\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"# Diccionario global para almacenar predicciones de partidos\n",
|
| 124 |
+
"predicciones_guardadas = {}\n",
|
| 125 |
+
"\n",
|
| 126 |
+
"def predecir(equipo_local, equipo_visitante):\n",
|
| 127 |
+
" global predicciones_guardadas # Para modificar la variable global\n",
|
| 128 |
+
" \n",
|
| 129 |
+
" clave_partido = (equipo_local, equipo_visitante)\n",
|
| 130 |
+
"\n",
|
| 131 |
+
" # ✅ Si la predicción ya existe, usarla\n",
|
| 132 |
+
" if clave_partido in predicciones_guardadas:\n",
|
| 133 |
+
" prob_max, resultado_max, resultado_html, estadisticas_html, tabla_historial_html = predicciones_guardadas[clave_partido]\n",
|
| 134 |
+
" else:\n",
|
| 135 |
+
" # ✅ Generar la predicción solo si no existe aún\n",
|
| 136 |
+
" prob_max = np.random.uniform(40, 60)\n",
|
| 137 |
+
" resultado_max = \"Victoria Local\" if prob_max > 50 else \"Victoria Visitante\"\n",
|
| 138 |
+
" color_resultado = \"green\" if prob_max > 50 else \"red\"\n",
|
| 139 |
+
" enfrentamientos = df[\n",
|
| 140 |
+
" ((df[\"Equipo_Local\"] == equipo_local) & (df[\"Equipo_Visitante\"] == equipo_visitante)) |\n",
|
| 141 |
+
" ((df[\"Equipo_Local\"] == equipo_visitante) & (df[\"Equipo_Visitante\"] == equipo_local))\n",
|
| 142 |
+
" ].sort_values(by=\"Fecha\", ascending=False).head(10)\n",
|
| 143 |
+
"\n",
|
| 144 |
+
" # ✅ Verificar si hay enfrentamientos previos\n",
|
| 145 |
+
" if enfrentamientos.empty:\n",
|
| 146 |
+
" print(f\"⚠️ No hay enfrentamientos previos entre {equipo_local} y {equipo_visitante}.\")\n",
|
| 147 |
+
" \n",
|
| 148 |
+
" # Retornar valores vacíos para evitar el error de Gradio\n",
|
| 149 |
+
" return (\n",
|
| 150 |
+
" f\"<p style='color:red;'><b>⚠️ No hay datos suficientes para predecir este partido.</b></p>\",\n",
|
| 151 |
+
" \"\",\n",
|
| 152 |
+
" \"<p style='color:red;'>No hay historial de enfrentamientos.</p>\"\n",
|
| 153 |
+
" )\n",
|
| 154 |
+
"\n",
|
| 155 |
+
" # ✅ Calcular promedio de goles en los enfrentamientos\n",
|
| 156 |
+
" goles_equipo_A = enfrentamientos.apply(\n",
|
| 157 |
+
" lambda row: row[\"Goles_Local\"] if row[\"Equipo_Local\"] == equipo_local else row[\"Goles_Visitante\"], axis=1\n",
|
| 158 |
+
" )\n",
|
| 159 |
+
" goles_equipo_B = enfrentamientos.apply(\n",
|
| 160 |
+
" lambda row: row[\"Goles_Local\"] if row[\"Equipo_Local\"] == equipo_visitante else row[\"Goles_Visitante\"], axis=1 \n",
|
| 161 |
+
" )\n",
|
| 162 |
+
" promedio_goles_equipo_A = goles_equipo_A.mean() if not goles_equipo_A.empty else 0\n",
|
| 163 |
+
" promedio_goles_equipo_B = goles_equipo_B.mean() if not goles_equipo_B.empty else 0\n",
|
| 164 |
+
"\n",
|
| 165 |
+
" \n",
|
| 166 |
+
" \n",
|
| 167 |
+
"\n",
|
| 168 |
+
" ultimos_10_local = df[df[\"Equipo_Local\"] == equipo_local].sort_values(by=\"Fecha\", ascending=False).head(10)\n",
|
| 169 |
+
" ultimos_10_visitante = df[df[\"Equipo_Visitante\"] == equipo_visitante].sort_values(by=\"Fecha\", ascending=False).head(10)\n",
|
| 170 |
+
"\n",
|
| 171 |
+
" prom_goles_local = ultimos_10_local[\"Goles_Local\"].mean()\n",
|
| 172 |
+
" prom_tiros_local = ultimos_10_local[\"Tiros_Puerta_Local\"].mean()\n",
|
| 173 |
+
" prom_corners_local = ultimos_10_local[\"Corners_Local\"].mean()\n",
|
| 174 |
+
"\n",
|
| 175 |
+
" prom_goles_visitante = ultimos_10_visitante[\"Goles_Visitante\"].mean() \n",
|
| 176 |
+
" prom_tiros_visitante = ultimos_10_visitante[\"Tiros_Puerta_Visitante\"].mean()\n",
|
| 177 |
+
" prom_corners_visitante = ultimos_10_visitante[\"Corners_Visitante\"].mean()\n",
|
| 178 |
+
"\n",
|
| 179 |
+
"\n",
|
| 180 |
+
" # ✅ Calcular la efectividad de gol (% de tiros que terminan en gol)\n",
|
| 181 |
+
" efectividad_local = ( prom_goles_local / prom_tiros_local * 100) if prom_tiros_local > 0 else 0\n",
|
| 182 |
+
" efectividad_visitante = (prom_goles_visitante / prom_tiros_visitante * 100) if prom_tiros_visitante > 0 else 0\n",
|
| 183 |
+
"\n",
|
| 184 |
+
" resultado_max = \"Victoria Local\" if prob_max > 50 else \"Victoria Visitante\"\n",
|
| 185 |
+
" color_resultado = \"green\" if prob_max > 50 else \"red\"\n",
|
| 186 |
+
"\n",
|
| 187 |
+
" resultado_html = f\"\"\"\n",
|
| 188 |
+
" <div style='display:flex; align-items:center; justify-content:center;'>\n",
|
| 189 |
+
" <div style='text-align:center;'>\n",
|
| 190 |
+
" {obtener_escudo(equipo_local)}<br>{equipo_local}\n",
|
| 191 |
+
" </div>\n",
|
| 192 |
+
" <div style='margin:0 20px;color:{color_resultado};font-size:20px;'>\n",
|
| 193 |
+
" <b>{resultado_max}: {prob_max:.2f}%</b>\n",
|
| 194 |
+
" </div>\n",
|
| 195 |
+
" <div style='text-align:center;'>\n",
|
| 196 |
+
" {obtener_escudo(equipo_visitante)}<br>{equipo_visitante}\n",
|
| 197 |
+
" </div>\n",
|
| 198 |
+
" </div>\n",
|
| 199 |
+
" \"\"\"\n",
|
| 200 |
+
"\n",
|
| 201 |
+
" estadisticas_html = f\"\"\"\n",
|
| 202 |
+
" <div style='padding:10px;'>\n",
|
| 203 |
+
" <p><b>🏟️ Estadio:</b> {estadios[equipo_local]['estadio']}</p>\n",
|
| 204 |
+
" <p><b>📊 Capacidad:</b> {estadios[equipo_local]['capacidad']} espectadores</p>\n",
|
| 205 |
+
" <hr style='width:60%;text-align:left;margin-left:0;'>\n",
|
| 206 |
+
" ⚽ <b>Promedio Goles Últimos 10 Partidos entre ellos:</b> {promedio_goles_equipo_A:.2f} | {promedio_goles_equipo_B:.2f}<br>\n",
|
| 207 |
+
" 🎯 <b>Promedio Tiros a Puerta (Últimos 10 Partidos como Local/Visitante)</b> {prom_tiros_local:.2f} | {prom_tiros_visitante:.2f}<br>\n",
|
| 208 |
+
" 🏳️ <b>Promodio Corners (Últimos 10 Partidos como Local/Visitante:</b> {prom_corners_local:.2f} | {prom_corners_visitante:.2f}<br>\n",
|
| 209 |
+
" 🎯 <b>Efectividad Gol(Últimos 10 Partidos como Local/Visitante)</b> {efectividad_local:.2f}% | {efectividad_visitante:.2f}%\n",
|
| 210 |
+
" \n",
|
| 211 |
+
" \"\"\"\n",
|
| 212 |
+
"\n",
|
| 213 |
+
" enfrentamientos[\"Resultado\"] = enfrentamientos.apply(\n",
|
| 214 |
+
" lambda x: f\"<span style='color:{asignar_color_resultado(x['Goles_Local'], x['Goles_Visitante'])};font-weight:bold'>{x['Goles_Local']} - {x['Goles_Visitante']}</span>\",\n",
|
| 215 |
+
" axis=1\n",
|
| 216 |
+
" )\n",
|
| 217 |
+
"\n",
|
| 218 |
+
" tabla_historial_html = enfrentamientos[['Fecha','Equipo_Local','Resultado','Equipo_Visitante']].rename(\n",
|
| 219 |
+
" columns={\"Equipo_Local\": \"Local\", \"Equipo_Visitante\": \"Visitante\"}\n",
|
| 220 |
+
" ).to_html(index=False, escape=False)\n",
|
| 221 |
+
"\n",
|
| 222 |
+
" # ✅ Guardar la predicción en el diccionario para no cambiar en el futuro\n",
|
| 223 |
+
" predicciones_guardadas[clave_partido] = (prob_max, resultado_max, resultado_html, estadisticas_html, tabla_historial_html)\n",
|
| 224 |
+
"\n",
|
| 225 |
+
" return resultado_html, estadisticas_html, tabla_historial_html\n",
|
| 226 |
+
"\n",
|
| 227 |
+
"\n",
|
| 228 |
+
"# Interfaz Gradio corregida completamente\n",
|
| 229 |
+
"with gr.Blocks() as app:\n",
|
| 230 |
+
" gr.Markdown(\"## ⚽ Predicción de Partidos Premier League\")\n",
|
| 231 |
+
"\n",
|
| 232 |
+
" equipos = list(estadios.keys())\n",
|
| 233 |
+
"\n",
|
| 234 |
+
" with gr.Row():\n",
|
| 235 |
+
" with gr.Column(scale=1):\n",
|
| 236 |
+
" equipo_local = gr.Dropdown(label=\"Local\", choices=equipos, value=equipos[0])\n",
|
| 237 |
+
" equipo_visitante = gr.Dropdown(label=\"Visitante\", choices=[e for e in equipos if e != equipos[0]])\n",
|
| 238 |
+
" boton_predecir = gr.Button(\"Predecir Resultado\")\n",
|
| 239 |
+
"\n",
|
| 240 |
+
" resultado_html = gr.HTML()\n",
|
| 241 |
+
"\n",
|
| 242 |
+
" with gr.Row():\n",
|
| 243 |
+
" estadisticas_html = gr.HTML()\n",
|
| 244 |
+
" tabla_historial_html = gr.HTML()\n",
|
| 245 |
+
"\n",
|
| 246 |
+
" def actualizar_visitante(equipo_local):\n",
|
| 247 |
+
" return gr.update(choices=[e for e in equipos if e != equipo_local])\n",
|
| 248 |
+
"\n",
|
| 249 |
+
" equipo_local.change(\n",
|
| 250 |
+
" actualizar_visitante,\n",
|
| 251 |
+
" inputs=equipo_local,\n",
|
| 252 |
+
" outputs=equipo_visitante\n",
|
| 253 |
+
" )\n",
|
| 254 |
+
"\n",
|
| 255 |
+
" boton_predecir.click(\n",
|
| 256 |
+
" predecir,\n",
|
| 257 |
+
" inputs=[equipo_local, equipo_visitante],\n",
|
| 258 |
+
" outputs=[resultado_html, estadisticas_html, tabla_historial_html]\n",
|
| 259 |
+
" )\n",
|
| 260 |
+
"\n",
|
| 261 |
+
"app.launch(debug=True)"
|
| 262 |
+
]
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"cell_type": "code",
|
| 266 |
+
"execution_count": 1,
|
| 267 |
+
"id": "1c8e96d1-d525-40ab-82ee-627726798928",
|
| 268 |
+
"metadata": {},
|
| 269 |
+
"outputs": [
|
| 270 |
+
{
|
| 271 |
+
"data": {
|
| 272 |
+
"text/plain": [
|
| 273 |
+
"0"
|
| 274 |
+
]
|
| 275 |
+
},
|
| 276 |
+
"execution_count": 1,
|
| 277 |
+
"metadata": {},
|
| 278 |
+
"output_type": "execute_result"
|
| 279 |
+
}
|
| 280 |
+
],
|
| 281 |
+
"source": [
|
| 282 |
+
"import os\n",
|
| 283 |
+
"os.system(\"jupyter nbconvert --to script --output app.py app.ipynb\")\n"
|
| 284 |
+
]
|
| 285 |
+
},
|
| 286 |
+
{
|
| 287 |
+
"cell_type": "code",
|
| 288 |
+
"execution_count": null,
|
| 289 |
+
"id": "80ae0895-65ad-4288-b427-09bdfcfac288",
|
| 290 |
+
"metadata": {},
|
| 291 |
+
"outputs": [],
|
| 292 |
+
"source": []
|
| 293 |
+
}
|
| 294 |
+
],
|
| 295 |
+
"metadata": {
|
| 296 |
+
"kernelspec": {
|
| 297 |
+
"display_name": "Python 3 (ipykernel)",
|
| 298 |
+
"language": "python",
|
| 299 |
+
"name": "python3"
|
| 300 |
+
},
|
| 301 |
+
"language_info": {
|
| 302 |
+
"codemirror_mode": {
|
| 303 |
+
"name": "ipython",
|
| 304 |
+
"version": 3
|
| 305 |
+
},
|
| 306 |
+
"file_extension": ".py",
|
| 307 |
+
"mimetype": "text/x-python",
|
| 308 |
+
"name": "python",
|
| 309 |
+
"nbconvert_exporter": "python",
|
| 310 |
+
"pygments_lexer": "ipython3",
|
| 311 |
+
"version": "3.12.3"
|
| 312 |
+
}
|
| 313 |
+
},
|
| 314 |
+
"nbformat": 4,
|
| 315 |
+
"nbformat_minor": 5
|
| 316 |
+
}
|