rodrigomasini commited on
Commit
43ee890
Β·
verified Β·
1 Parent(s): fd9eb06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -76
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
- demo = gr.Blocks(css=custom_css)
29
- with demo:
30
- gr.HTML(LOGO, elem_classes="logo")
31
- gr.HTML(TITLE, elem_classes="title")
32
- gr.Markdown(INTRODUCTION, elem_classes="descriptive-text")
33
- ####################### HARDWARE TABS #######################
34
- with gr.Tabs(elem_classes="tabs"):
35
- for id, (machine, hardware) in enumerate(MACHINE_TO_HARDWARE.items()):
36
- with gr.TabItem(hardware, id=id):
37
- ####################### CONTROL PANEL #######################
38
- (
39
- filter_button,
40
- machine_textbox,
41
- search_bar,
42
- score_slider,
43
- memory_slider,
44
- backend_checkboxes,
45
- datatype_checkboxes,
46
- optimization_checkboxes,
47
- quantization_checkboxes,
48
- ) = create_control_panel()
49
- ####################### HARDWARE SUBTABS #######################
50
- with gr.Tabs(elem_classes="subtabs"):
51
- llm_perf_df = get_llm_perf_df(machine=machine)
52
- ####################### LEADERBOARD TAB #######################
53
- with gr.TabItem("Leaderboard πŸ…", id=0):
54
- leaderboard_table = create_leaderboard_table(llm_perf_df)
55
- lat_score_mem_plot = create_lat_score_mem_plot(llm_perf_df)
56
- ####################### BETTERTRANSFORMER SPEEDUP TAB #######################
57
- with gr.TabItem("BetterTransformer πŸ“ˆ", id=2):
58
- bt_prefill_plot, bt_decode_plot = create_bt_plots(llm_perf_df)
59
- with gr.TabItem("FlashAttentionV2 πŸ“ˆ", id=3):
60
- fa2_prefill_plot, fa2_decode_plot = create_fa2_plots(llm_perf_df)
61
- with gr.TabItem("Custom Quantization Kernels πŸ“ˆ", id=4):
62
- quant_prefill_plot, quant_decode_plot = create_quant_plots(llm_perf_df)
63
-
64
- ####################### CONTROL CALLBACK #######################
65
- create_control_callback(
66
- filter_button,
67
- # inputs
68
- machine_textbox,
69
- search_bar,
70
- score_slider,
71
- memory_slider,
72
- backend_checkboxes,
73
- datatype_checkboxes,
74
- optimization_checkboxes,
75
- quantization_checkboxes,
76
- # outputs
77
- leaderboard_table,
78
- lat_score_mem_plot,
79
- bt_prefill_plot,
80
- bt_decode_plot,
81
- fa2_prefill_plot,
82
- fa2_decode_plot,
83
- quant_prefill_plot,
84
- quant_decode_plot,
85
- )
86
- ####################### ABOUT TAB #######################
87
- with gr.TabItem("About πŸ“–", id=3):
88
- gr.HTML(ABOUT, elem_classes="descriptive-text")
89
- gr.Markdown(EXAMPLE_CONFIG, elem_classes="descriptive-text")
90
- ####################### CITATION
91
- with gr.Row():
92
- with gr.Accordion("πŸ“™ Citation", open=False):
93
- citation_button = gr.Textbox(
94
- value=CITATION_BUTTON,
95
- label=CITATION_BUTTON_LABEL,
96
- elem_id="citation-button",
97
- show_copy_button=True,
98
- )
99
-
100
- if __name__ == "__main__":
101
- # Launch demo
102
- demo.queue().launch()
 
 
 
 
 
 
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()