Spaces:
Runtime error
Runtime error
File size: 4,164 Bytes
c8763bd 43ee890 c8763bd 5af8a7d 134a499 ab5f5f1 eed3175 ab5f5f1 eed3175 6f3a090 0f1bf97 ab5f5f1 0f1bf97 c8763bd efc3d5b 7406034 ab5f5f1 b3a1bf0 4564527 43ee890 6232d80 66ed621 6232d80 66ed621 6232d80 8c0b755 3f5d9da 6232d80 3f5d9da 964afcc 3f5d9da 43ee890 3f5d9da 43ee890 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
import os
from apscheduler.schedulers.background import BackgroundScheduler
import gradio as gr
import pandas as pd
from src.control_panel import create_control_panel, create_control_callback
from src.leaderboard import (
create_leaderboard_table,
COLS,
TYPES,
)
from src.llm_perf import get_llm_perf_df
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)
def restart_space():
API.restart_space(repo_id=REPO_ID, token=HF_TOKEN)
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 preprocess_dataframe(df):
# Apply the `remove_invalid_unicode` function to all string columns
for column in df.columns:
if df[column].dtype == 'object': # Checking for string columns
df[column] = df[column].apply(remove_invalid_unicode)
return df
# Fetch and preprocess the leaderboard DataFrame
llm_perf_df = get_llm_perf_df()
llm_perf_df = preprocess_dataframe(llm_perf_df)
# Create the leaderboard table
leaderboard_table = create_leaderboard_table(llm_perf_df)
hidden_leaderboard_table_for_search = gr.components.Dataframe(
leaderboard_table,
headers=COLS,
datatype=TYPES,
visible=False,
line_breaks=False,
interactive=False
)
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_table[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() |