import gradio as gr import pandas as pd # Define the columns for the UGI Leaderboard UGI_COLS = [ '#P', 'Model', 'UGI 🏆', 'W/10 👍', 'Unruly', 'Internet', 'CrimeStats', 'Stories/Jokes', 'PolContro' ] # Load the leaderboard data from a CSV file def load_leaderboard_data(csv_file_path): try: df = pd.read_csv(csv_file_path) # Create hyperlinks in the Model column using HTML tags with inline CSS for styling df['Model'] = df.apply(lambda row: f'{row["Model"]}' if pd.notna(row["Link"]) else row["Model"], axis=1) # Drop the 'Link' column as it's no longer needed df.drop(columns=['Link'], inplace=True) return df except Exception as e: print(f"Error loading CSV file: {e}") return pd.DataFrame(columns=UGI_COLS) # Return an empty dataframe with the correct columns # Update the leaderboard table based on the search query and parameter range filters def update_table(df: pd.DataFrame, query: str, param_ranges: list) -> pd.DataFrame: filtered_df = df if any(param_ranges): conditions = [] for param_range in param_ranges: if param_range == '~1.5': conditions.append((filtered_df['Params'] < 2.5)) elif param_range == '~3': conditions.append(((filtered_df['Params'] >= 2.5) & (filtered_df['Params'] < 6))) elif param_range == '~7': conditions.append(((filtered_df['Params'] >= 6) & (filtered_df['Params'] < 9.5))) elif param_range == '~13': conditions.append(((filtered_df['Params'] >= 9.5) & (filtered_df['Params'] < 16))) elif param_range == '~20': conditions.append(((filtered_df['Params'] >= 16) & (filtered_df['Params'] < 28))) elif param_range == '~34': conditions.append(((filtered_df['Params'] >= 28) & (filtered_df['Params'] < 40))) elif param_range == '~50': conditions.append(((filtered_df['Params'] >= 40) & (filtered_df['Params'] < 60))) elif param_range == '~70+': conditions.append((filtered_df['Params'] >= 60)) if conditions: filtered_df = filtered_df[pd.concat(conditions, axis=1).any(axis=1)] else: filtered_df = filtered_df[filtered_df['Params'].notna()] else: filtered_df = filtered_df[filtered_df['Params'].isna()] if query: filtered_df = filtered_df[filtered_df.apply(lambda row: query.lower() in row.to_string().lower(), axis=1)] return filtered_df[UGI_COLS] # Return only the columns defined in UGI_COLS # Define the Gradio interface GraInter = gr.Blocks() with GraInter: gr.HTML("""