# app.py import gradio as gr import pandas as pd import requests import xgboost as xgb from huggingface_hub import hf_hub_download from app_training_df_getter import create_app_user_training_df import os import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Define champion list for dropdowns CHAMPIONS = [ "Aatrox", "Ahri", "Akali", "Akshan", "Alistar", "Amumu", "Anivia", "Annie", "Aphelios", "Ashe", "Aurelion Sol", "Azir", "Bard", "Bel'Veth", "Blitzcrank", "Brand", "Braum", "Caitlyn", "Camille", "Cassiopeia", "Cho'Gath", "Corki", "Darius", "Diana", "Dr. Mundo", "Draven", "Ekko", "Elise", "Evelynn", "Ezreal", "Fiddlesticks", "Fiora", "Fizz", "Galio", "Gangplank", "Garen", "Gnar", "Gragas", "Graves", "Gwen", "Hecarim", "Heimerdinger", "Illaoi", "Irelia", "Ivern", "Janna", "Jarvan IV", "Jax", "Jayce", "Jhin", "Jinx", "Kai'Sa", "Kalista", "Karma", "Karthus", "Kassadin", "Katarina", "Kayle", "Kayn", "Kennen", "Kha'Zix", "Kindred", "Kled", "Kog'Maw", "KSante", "LeBlanc", "Lee Sin", "Leona", "Lillia", "Lissandra", "Lucian", "Lulu", "Lux", "Malphite", "Malzahar", "Maokai", "Master Yi", "Milio", "Miss Fortune", "Mordekaiser", "Morgana", "Naafiri", "Nami", "Nasus", "Nautilus", "Neeko", "Nidalee", "Nilah", "Nocturne", "Nunu & Willump", "Olaf", "Orianna", "Ornn", "Pantheon", "Poppy", "Pyke", "Qiyana", "Quinn", "Rakan", "Rammus", "Rek'Sai", "Rell", "Renata Glasc", "Renekton", "Rengar", "Riven", "Rumble", "Ryze", "Samira", "Sejuani", "Senna", "Seraphine", "Sett", "Shaco", "Shen", "Shyvana", "Singed", "Sion", "Sivir", "Skarner", "Sona", "Soraka", "Swain", "Sylas", "Syndra", "Tahm Kench", "Taliyah", "Talon", "Taric", "Teemo", "Thresh", "Tristana", "Trundle", "Tryndamere", "Twisted Fate", "Twitch", "Udyr", "Urgot", "Varus", "Vayne", "Veigar", "Vel'Koz", "Vex", "Vi", "Viego", "Viktor", "Vladimir", "Volibear", "Warwick", "Wukong", "Xayah", "Xerath", "Xin Zhao", "Yasuo", "Yone", "Yorick", "Yuumi", "Zac", "Zed", "Zeri", "Ziggs", "Zilean", "Zoe", "Zyra" ] # Load model try: model_path = hf_hub_download( repo_id="ivwhy/champion-predictor-model", filename="champion_predictor.json" ) model = xgb.Booster() model.load_model(model_path) except Exception as e: print(f"Error loading model: {e}") model = None # Functions def get_user_training_df(player_opgg_url): try: print("========= Inside get_user_training_df(player_opgg_url) ============= \n") print("player_opgg_url: ", player_opgg_url, "\n") # Add input validation if not player_opgg_url or not isinstance(player_opgg_url, str): return "Invalid URL provided" training_df = create_app_user_training_df(player_opgg_url) return training_df except Exception as e: # Add more detailed error information import traceback error_trace = traceback.format_exc() print(f"Full error trace:\n{error_trace}") return f"Error getting training data: {str(e)}" #return f"Error getting training data: {e}" def show_stats(player_opgg_url): """Display player statistics and recent matches""" if not player_opgg_url: return "Please enter a player link to OPGG", None try: training_features = get_user_training_df(player_opgg_url) if isinstance(training_features, str): # Error message return training_features, None wins = training_features['result'].sum() losses = len(training_features) - wins winrate = f"{(wins / len(training_features)) * 100:.0f}%" favorite_champions = ( training_features['champion'] .value_counts() .head(3) .index.tolist() ) stats_html = f"""
Wins: {wins} | Losses: {losses}
Winrate: {winrate}
Favorite Champions: {', '.join(favorite_champions)}