CultriX commited on
Commit
35bf268
β€’
1 Parent(s): bc527a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -18
app.py CHANGED
@@ -16,28 +16,40 @@ def cached_model_info(api, model):
16
 
17
  def convert_markdown_table_to_dataframe(md_content):
18
  cleaned_content = re.sub(r'\|\s*$', '', re.sub(r'^\|\s*', '', md_content, flags=re.MULTILINE), flags=re.MULTILINE)
19
- df = pd.read_csv(StringIO(cleaned_content), sep="\|", engine='python', skipinitialspace=True)
20
- df.columns = df.columns.str.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- model_link_pattern = r'\[(.*?)\]\((.*?)\)\s*\[.*?\]\(.*?\)'
23
- # Correctly process 'Model' column to extract URLs and model names
24
- df['URL'] = df['Model'].apply(lambda x: re.search(model_link_pattern, x).group(2) if re.search(model_link_pattern, x) else None)
25
- df['Model'] = df['Model'].apply(lambda x: re.sub(model_link_pattern, r'\1', x))
26
  return df
27
 
28
  def get_and_update_model_info(df):
29
  api = HfApi()
 
 
30
  for index, row in df.iterrows():
31
- model_info = cached_model_info(api, row['Model'].strip())
32
- if model_info:
33
- df.at[index, 'Likes'] = model_info.likes
34
- df.at[index, 'Tags'] = ', '.join(model_info.tags)
35
- else:
36
- df.at[index, 'Likes'] = -1
37
- df.at[index, 'Tags'] = ''
38
  return df
39
 
40
  def calculate_highest_combined_score(data, column):
 
 
 
41
  scores = data[column].dropna().tolist()
42
  models = data['Model'].tolist()
43
  top_combinations = {r: [] for r in range(2, 7)}
@@ -51,8 +63,8 @@ def calculate_highest_combined_score(data, column):
51
 
52
  def display_highest_combined_scores(data, score_columns):
53
  for column in score_columns:
54
- if column in data.columns:
55
- _, top_combinations = calculate_highest_combined_score(data, column)
56
  st.subheader(f"Top Combinations for {column}")
57
  for r, combinations in top_combinations.items():
58
  st.write(f"**Number of Models: {r}**")
@@ -60,6 +72,7 @@ def display_highest_combined_scores(data, score_columns):
60
  st.write(f"Score: {score}, Models: {', '.join(combination)}")
61
 
62
 
 
63
  # Function to create bar chart for a given category
64
  def create_bar_chart(df, category):
65
  """Create and display a bar chart for a given category."""
@@ -88,16 +101,18 @@ def create_bar_chart(df, category):
88
  def main():
89
  st.title("Model Leaderboard")
90
  st.markdown("Displaying top combinations of models based on scores.")
91
- # Placeholder for actual markdown content
92
- content = """Your markdown content here"""
93
  if content:
94
  df = convert_markdown_table_to_dataframe(content)
95
  df = get_and_update_model_info(df)
96
  score_columns = ['Average', 'AGIEval', 'GPT4All', 'TruthfulQA', 'Bigbench']
97
  for col in score_columns:
98
- df[col] = pd.to_numeric(df[col], errors='coerce')
 
99
  display_highest_combined_scores(df, score_columns)
100
 
 
101
  # Create tabs for leaderboard and about section
102
  content = create_yall()
103
  tab1, tab2 = st.tabs(["πŸ† Leaderboard", "πŸ“ About"])
 
16
 
17
  def convert_markdown_table_to_dataframe(md_content):
18
  cleaned_content = re.sub(r'\|\s*$', '', re.sub(r'^\|\s*', '', md_content, flags=re.MULTILINE), flags=re.MULTILINE)
19
+ df = pd.read_csv(StringIO(cleaned_content), sep="\|", engine='python')
20
+ df.columns = [col.strip() for col in df.columns]
21
+
22
+ # Initialize empty columns for URL and Model if not already present
23
+ if 'Model' not in df.columns:
24
+ df['Model'] = None
25
+ if 'URL' not in df.columns:
26
+ df['URL'] = None
27
+
28
+ model_link_pattern = r'\[(.*?)\]\((.*?)\)'
29
+ for index, row in df.iterrows():
30
+ match = re.search(model_link_pattern, row['Model'])
31
+ if match:
32
+ df.at[index, 'Model'] = match.group(1)
33
+ df.at[index, 'URL'] = match.group(2)
34
 
 
 
 
 
35
  return df
36
 
37
  def get_and_update_model_info(df):
38
  api = HfApi()
39
+ df['Likes'] = -1 # Default value for Likes
40
+ df['Tags'] = '' # Default value for Tags
41
  for index, row in df.iterrows():
42
+ if pd.notnull(row['Model']):
43
+ model_info = cached_model_info(api, row['Model'].strip())
44
+ if model_info:
45
+ df.at[index, 'Likes'] = model_info.likes
46
+ df.at[index, 'Tags'] = ', '.join(model_info.tags)
 
 
47
  return df
48
 
49
  def calculate_highest_combined_score(data, column):
50
+ # Ensure the column exists and has numeric data
51
+ if column not in data.columns or not pd.api.types.is_numeric_dtype(data[column]):
52
+ return column, {}
53
  scores = data[column].dropna().tolist()
54
  models = data['Model'].tolist()
55
  top_combinations = {r: [] for r in range(2, 7)}
 
63
 
64
  def display_highest_combined_scores(data, score_columns):
65
  for column in score_columns:
66
+ _, top_combinations = calculate_highest_combined_score(data, column)
67
+ if top_combinations:
68
  st.subheader(f"Top Combinations for {column}")
69
  for r, combinations in top_combinations.items():
70
  st.write(f"**Number of Models: {r}**")
 
72
  st.write(f"Score: {score}, Models: {', '.join(combination)}")
73
 
74
 
75
+
76
  # Function to create bar chart for a given category
77
  def create_bar_chart(df, category):
78
  """Create and display a bar chart for a given category."""
 
101
  def main():
102
  st.title("Model Leaderboard")
103
  st.markdown("Displaying top combinations of models based on scores.")
104
+ content = """Your markdown content here""" # Placeholder for actual markdown content
105
+
106
  if content:
107
  df = convert_markdown_table_to_dataframe(content)
108
  df = get_and_update_model_info(df)
109
  score_columns = ['Average', 'AGIEval', 'GPT4All', 'TruthfulQA', 'Bigbench']
110
  for col in score_columns:
111
+ if col in df.columns:
112
+ df[col] = pd.to_numeric(df[col], errors='coerce')
113
  display_highest_combined_scores(df, score_columns)
114
 
115
+
116
  # Create tabs for leaderboard and about section
117
  content = create_yall()
118
  tab1, tab2 = st.tabs(["πŸ† Leaderboard", "πŸ“ About"])