import os from apscheduler.schedulers.background import BackgroundScheduler import gradio as gr from src.control_panel import create_control_panel, create_control_callback from src.latency_score_memory import create_lat_score_mem_plot from src.quantization_kernels import create_quant_plots from src.leaderboard import create_leaderboard_table from src.bettertransformer import create_bt_plots from src.flashattentionv2 import create_fa2_plots from src.llm_perf import get_llm_perf_df from src.assets import custom_css from src.content import ( LOGO, TITLE, ABOUT, INTRODUCTION, EXAMPLE_CONFIG, CITATION_BUTTON, CITATION_BUTTON_LABEL, ) MACHINE_TO_HARDWARE = {"hf-dgx-01": "A100-80GB-275W 🖥️", "audace": "RTX4090-24GB-450W 💻"} HF_TOKEN = os.environ.get("HF_TOKEN", None) llm_perf_df = get_llm_perf_df(machine="hf-dgx-01") leaderboard_table = create_leaderboard_table(llm_perf_df) import unicodedata def is_valid_unicode(char): try: unicodedata.name(char) return True # Valid Unicode character except ValueError: return False # Invalid Unicode character def remove_invalid_unicode(input_string): if isinstance(input_string, str): valid_chars = [char for char in input_string if is_valid_unicode(char)] return ''.join(valid_chars) else: return input_string # Return non-string values as is def display(x, y): # Assuming df is your DataFrame for column in leaderboard_table.columns: if leaderboard_table[column].dtype == 'object': leaderboard_table[column] = leaderboard_table[column].apply(remove_invalid_unicode) subset_df = leaderboard_df[COLS] return subset_df dummy1 = gr.Textbox(visible=False) INTRODUCTION_TEXT = """ This is a copied space from LLM Trustworthy Leaderboard. Instead of displaying the results as table this space was modified to simply provides a gradio API interface. Using the following python script below, users can access the full leaderboard data easily. Python on how to access the data: ```python # Import dependencies from gradio_client import Client # Initialize the Gradio client with the API URL client = Client("https://rodrigomasini-data-only-llm-perf-leaderboard.hf.space/") try: # Perform the API call response = client.predict("","", api_name='/predict') # Check if response it's directly accessible if len(response) > 0: print("Response received!") headers = response.get('headers', []) data = response.get('data', []) print(headers) # Remove commenst if you want to download the dataset and save in csv format # Specify the path to your CSV file #csv_file_path = 'llm-perf-benchmark.csv' # Open the CSV file for writing #with open(csv_file_path, mode='w', newline='', encoding='utf-8') as file: # writer = csv.writer(file) # Write the headers # writer.writerow(headers) # Write the data # for row in data: # writer.writerow(row) #print(f"Results saved to {csv_file_path}") # If the above line prints a string that looks like JSON, you can parse it with json.loads(response) # Otherwise, you might need to adjust based on the actual structure of `response` except Exception as e: print(f"An error occurred: {e}") ``` """ interface = gr.Interface( fn=display, inputs=[gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text"), dummy1], outputs=[hidden_leaderboard_table_for_search] ) scheduler = BackgroundScheduler() scheduler.add_job(restart_space, "interval", seconds=1800) scheduler.start() interface.launch()