Thermostatic commited on
Commit
4a1f5da
·
verified ·
1 Parent(s): 8f1e4ff

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +38 -14
src/streamlit_app.py CHANGED
@@ -1,15 +1,35 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
 
4
  # Page configuration
5
  st.set_page_config(layout="wide", page_title="TranslateBench EN-ES Leaderboard")
6
 
7
  # Caching the data loading function
8
- @st.cache_data
9
- def load_data(file_path="model_benchmark_summary.csv"):
10
- """Loads and preprocesses the benchmark data."""
11
  try:
12
- df = pd.read_csv(file_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # Extract provider from Model Name
14
  df['Provider'] = df['Model Name'].apply(lambda x: x.split('_')[0].capitalize())
15
  # Ensure score columns are numeric
@@ -17,22 +37,20 @@ def load_data(file_path="model_benchmark_summary.csv"):
17
  for col in score_cols:
18
  df[col] = pd.to_numeric(df[col], errors='coerce')
19
  return df
20
- except FileNotFoundError:
21
- st.error(f"Error: The file '{file_path}' was not found. Please make sure it's in the same directory as the script.")
22
- return None
23
  except Exception as e:
24
- st.error(f"An error occurred while loading or processing the data: {e}")
25
  return None
26
 
27
  # --- Main Application ---
28
  st.title("🏆 TranslateBench EN-ES Leaderboard")
29
  st.markdown("""
30
  This leaderboard shows the performance of various models on the English-to-Spanish translation task.
 
31
  You can sort the table by different metrics and filter by model provider.
32
  """)
33
 
34
  # Load data
35
- data_df = load_data()
36
 
37
  if data_df is not None:
38
  # --- Sidebar for Controls ---
@@ -79,10 +97,14 @@ if data_df is not None:
79
  delta=f"{top_model[sort_by]:.4f} ({sort_by})",
80
  delta_color="off" # No up/down arrow needed here
81
  )
 
82
  cols = st.columns(len(sortable_metrics))
83
  for i, metric in enumerate(sortable_metrics):
84
  with cols[i]:
85
- st.metric(label=metric, value=f"{top_model[metric]:.4f}")
 
 
 
86
  else:
87
  st.info("No data to display for top performer based on current filters.")
88
 
@@ -97,8 +119,10 @@ if data_df is not None:
97
  formatter = {col: "{:.4f}" for col in sortable_metrics}
98
 
99
  if not sorted_df.empty:
 
 
100
  st.dataframe(
101
- sorted_df[display_columns].style.format(formatter),
102
  use_container_width=True,
103
  hide_index=True,
104
  )
@@ -106,12 +130,12 @@ if data_df is not None:
106
  st.info("No models match the current filter criteria.")
107
 
108
  # --- Show Raw Data (Optional) ---
109
- if st.checkbox("Show Raw Data (Unsorted, Unfiltered)"):
110
  st.subheader("Raw Data")
111
  st.dataframe(data_df)
112
 
113
  else:
114
- st.warning("Data could not be loaded. Please check the console for errors and ensure the CSV file is correct.")
115
 
116
  st.markdown("---")
117
- st.markdown("Created with Streamlit and Pandas.")
 
1
  import streamlit as st
2
  import pandas as pd
3
+ from datasets import load_dataset # Import the Hugging Face datasets library
4
 
5
  # Page configuration
6
  st.set_page_config(layout="wide", page_title="TranslateBench EN-ES Leaderboard")
7
 
8
  # Caching the data loading function
9
+ @st.cache_data # Use st.cache_data for dataframes and serializable objects
10
+ def load_data_from_hf():
11
+ """Loads and preprocesses the benchmark data from Hugging Face."""
12
  try:
13
+ st.info("Fetching data from Hugging Face (Thermostatic/TranslateBench-EN-ES)... This may take a moment.")
14
+ # Load the specific CSV file from the dataset
15
+ # The 'data_files' argument points to the specific file within the dataset repository.
16
+ # 'load_dataset' returns a DatasetDict. For a single CSV, it's typically under the 'train' key.
17
+ dataset_dict = load_dataset("Thermostatic/TranslateBench-EN-ES", data_files="model_benchmark_summary.csv")
18
+
19
+ # Access the dataset (it will be the 'train' split by default for a single file)
20
+ if 'train' in dataset_dict:
21
+ dataset = dataset_dict['train']
22
+ else:
23
+ # Fallback in case the default split name isn't 'train'
24
+ # This gets the first (and likely only) key in the DatasetDict
25
+ first_split_name = list(dataset_dict.keys())[0]
26
+ dataset = dataset_dict[first_split_name]
27
+ st.warning(f"Using split '{first_split_name}' as 'train' split was not found.")
28
+
29
+ df = dataset.to_pandas()
30
+ st.success("Data loaded successfully from Hugging Face!")
31
+
32
+ # --- Preprocessing (same as your original code) ---
33
  # Extract provider from Model Name
34
  df['Provider'] = df['Model Name'].apply(lambda x: x.split('_')[0].capitalize())
35
  # Ensure score columns are numeric
 
37
  for col in score_cols:
38
  df[col] = pd.to_numeric(df[col], errors='coerce')
39
  return df
 
 
 
40
  except Exception as e:
41
+ st.error(f"An error occurred while loading or processing data from Hugging Face: {e}")
42
  return None
43
 
44
  # --- Main Application ---
45
  st.title("🏆 TranslateBench EN-ES Leaderboard")
46
  st.markdown("""
47
  This leaderboard shows the performance of various models on the English-to-Spanish translation task.
48
+ Data is sourced directly from the [Thermostatic/TranslateBench-EN-ES](https://huggingface.co/datasets/Thermostatic/TranslateBench-EN-ES) dataset on Hugging Face.
49
  You can sort the table by different metrics and filter by model provider.
50
  """)
51
 
52
  # Load data
53
+ data_df = load_data_from_hf()
54
 
55
  if data_df is not None:
56
  # --- Sidebar for Controls ---
 
97
  delta=f"{top_model[sort_by]:.4f} ({sort_by})",
98
  delta_color="off" # No up/down arrow needed here
99
  )
100
+ # Ensure all sortable_metrics exist in the top_model Series before trying to access them
101
  cols = st.columns(len(sortable_metrics))
102
  for i, metric in enumerate(sortable_metrics):
103
  with cols[i]:
104
+ if metric in top_model:
105
+ st.metric(label=metric, value=f"{top_model[metric]:.4f}")
106
+ else:
107
+ st.metric(label=metric, value="N/A")
108
  else:
109
  st.info("No data to display for top performer based on current filters.")
110
 
 
119
  formatter = {col: "{:.4f}" for col in sortable_metrics}
120
 
121
  if not sorted_df.empty:
122
+ # Ensure only existing columns are selected for display
123
+ existing_display_columns = [col for col in display_columns if col in sorted_df.columns]
124
  st.dataframe(
125
+ sorted_df[existing_display_columns].style.format(formatter),
126
  use_container_width=True,
127
  hide_index=True,
128
  )
 
130
  st.info("No models match the current filter criteria.")
131
 
132
  # --- Show Raw Data (Optional) ---
133
+ if st.checkbox("Show Raw Data (Downloaded, Unsorted, Unfiltered)"):
134
  st.subheader("Raw Data")
135
  st.dataframe(data_df)
136
 
137
  else:
138
+ st.warning("Data could not be loaded from Hugging Face. Please check the console for errors, your internet connection, and ensure the dataset/file path is correct.")
139
 
140
  st.markdown("---")
141
+ st.markdown("Created with Streamlit, Pandas, and data from Hugging Face Datasets.")