Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
|
3 |
import gradio as gr
|
4 |
|
5 |
from src.control_panel import create_control_panel, create_control_callback
|
@@ -25,78 +25,83 @@ MACHINE_TO_HARDWARE = {"hf-dgx-01": "A100-80GB-275W π₯οΈ", "audace": "RTX4090
|
|
25 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
3 |
import gradio as gr
|
4 |
|
5 |
from src.control_panel import create_control_panel, create_control_callback
|
|
|
25 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
26 |
|
27 |
|
28 |
+
llm_perf_df = get_llm_perf_df(machine="hf-dgx-01")
|
29 |
+
leaderboard_table = create_leaderboard_table(llm_perf_df)
|
30 |
+
|
31 |
+
import unicodedata
|
32 |
+
|
33 |
+
def is_valid_unicode(char):
|
34 |
+
try:
|
35 |
+
unicodedata.name(char)
|
36 |
+
return True # Valid Unicode character
|
37 |
+
except ValueError:
|
38 |
+
return False # Invalid Unicode character
|
39 |
+
|
40 |
+
def remove_invalid_unicode(input_string):
|
41 |
+
if isinstance(input_string, str):
|
42 |
+
valid_chars = [char for char in input_string if is_valid_unicode(char)]
|
43 |
+
return ''.join(valid_chars)
|
44 |
+
else:
|
45 |
+
return input_string # Return non-string values as is
|
46 |
+
|
47 |
+
def display(x, y):
|
48 |
+
# Assuming df is your DataFrame
|
49 |
+
for column in leaderboard_table.columns:
|
50 |
+
if leaderboard_table[column].dtype == 'object':
|
51 |
+
leaderboard_table[column] = leaderboard_table[column].apply(remove_invalid_unicode)
|
52 |
+
|
53 |
+
subset_df = leaderboard_df[COLS]
|
54 |
+
return subset_df
|
55 |
+
|
56 |
+
dummy1 = gr.Textbox(visible=False)
|
57 |
+
|
58 |
+
INTRODUCTION_TEXT = """
|
59 |
+
This is a copied space from LLM Trustworthy Leaderboard. Instead of displaying
|
60 |
+
the results as table this space was modified to simply provides a gradio API interface.
|
61 |
+
Using the following python script below, users can access the full leaderboard data easily.
|
62 |
+
Python on how to access the data:
|
63 |
+
```python
|
64 |
+
# Import dependencies
|
65 |
+
from gradio_client import Client
|
66 |
+
# Initialize the Gradio client with the API URL
|
67 |
+
client = Client("https://rodrigomasini-data-only-llm-perf-leaderboard.hf.space/")
|
68 |
+
try:
|
69 |
+
# Perform the API call
|
70 |
+
response = client.predict("","", api_name='/predict')
|
71 |
+
# Check if response it's directly accessible
|
72 |
+
if len(response) > 0:
|
73 |
+
print("Response received!")
|
74 |
+
headers = response.get('headers', [])
|
75 |
+
data = response.get('data', [])
|
76 |
+
print(headers)
|
77 |
+
# Remove commenst if you want to download the dataset and save in csv format
|
78 |
+
# Specify the path to your CSV file
|
79 |
+
#csv_file_path = 'llm-perf-benchmark.csv'
|
80 |
+
# Open the CSV file for writing
|
81 |
+
#with open(csv_file_path, mode='w', newline='', encoding='utf-8') as file:
|
82 |
+
# writer = csv.writer(file)
|
83 |
+
# Write the headers
|
84 |
+
# writer.writerow(headers)
|
85 |
+
# Write the data
|
86 |
+
# for row in data:
|
87 |
+
# writer.writerow(row)
|
88 |
+
#print(f"Results saved to {csv_file_path}")
|
89 |
+
# If the above line prints a string that looks like JSON, you can parse it with json.loads(response)
|
90 |
+
# Otherwise, you might need to adjust based on the actual structure of `response`
|
91 |
+
except Exception as e:
|
92 |
+
print(f"An error occurred: {e}")
|
93 |
+
```
|
94 |
+
"""
|
95 |
+
|
96 |
+
interface = gr.Interface(
|
97 |
+
fn=display,
|
98 |
+
inputs=[gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text"), dummy1],
|
99 |
+
outputs=[hidden_leaderboard_table_for_search]
|
100 |
+
)
|
101 |
+
|
102 |
+
scheduler = BackgroundScheduler()
|
103 |
+
scheduler.add_job(restart_space, "interval", seconds=1800)
|
104 |
+
|
105 |
+
scheduler.start()
|
106 |
+
|
107 |
+
interface.launch()
|