CultriX commited on
Commit
c56b33e
·
verified ·
1 Parent(s): 4aa97c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -190
app.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  import pandas as pd
2
  import matplotlib.pyplot as plt
3
  import seaborn as sns
@@ -11,8 +15,8 @@ import zipfile
11
  from PIL import Image
12
  from io import BytesIO
13
 
14
-
15
- # Input data with links to Hugging Face repositories
16
  data_full = [
17
  ['CultriX/Qwen2.5-14B-SLERPv7', 'https://huggingface.co/CultriX/Qwen2.5-14B-SLERPv7', 0.7205, 0.8272, 0.7541, 0.6581, 0.5, 0.729],
18
  ['djuna/Q2.5-Veltha-14B-0.5', 'https://huggingface.co/djuna/Q2.5-Veltha-14B-0.5', 0.7492, 0.8386, 0.7305, 0.598, 0.43, 0.7817],
@@ -40,17 +44,15 @@ data_full = [
40
  ['CultriX/Qwen2.5-14B-Wernickev7', 'https://huggingface.co/CultriX/Qwen2.5-14B-Wernickev7', 0.7147, 0.7599, 0.6097, 0.7056, 0.57, 0.7164],
41
  ['CultriX/Qwen2.5-14B-FinalMerge-tmp2', 'https://huggingface.co/CultriX/Qwen2.5-14B-FinalMerge-tmp2', 0.7255, 0.8192, 0.7535, 0.6671, 0.5, 0.7612],
42
  ]
43
-
44
  columns = ["Model Configuration", "Model Link", "tinyArc", "tinyHellaswag", "tinyMMLU", "tinyTruthfulQA", "tinyTruthfulQA_mc1", "tinyWinogrande"]
45
-
46
- # Convert to DataFrame
47
  df_full = pd.DataFrame(data_full, columns=columns)
48
 
49
- # Visualization and analytics functions
 
 
50
  def plot_average_scores():
51
  df_full["Average Score"] = df_full.iloc[:, 2:].mean(axis=1)
52
  df_avg_sorted = df_full.sort_values(by="Average Score", ascending=False)
53
-
54
  plt.figure(figsize=(12, 8))
55
  plt.barh(df_avg_sorted["Model Configuration"], df_avg_sorted["Average Score"])
56
  plt.title("Average Performance of Models Across Tasks", fontsize=16)
@@ -59,25 +61,15 @@ def plot_average_scores():
59
  plt.gca().invert_yaxis()
60
  plt.grid(axis='x', linestyle='--', alpha=0.7)
61
  plt.tight_layout()
62
-
63
- img_buffer = io.BytesIO()
64
- plt.savefig(img_buffer, format='png')
65
- img_buffer.seek(0)
66
- img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
67
- plt.close()
68
-
69
- pil_image = Image.open(BytesIO(base64.b64decode(img_base64)))
70
- return pil_image, "average_performance.png"
71
-
72
 
 
73
  def plot_task_performance():
74
  df_full_melted = df_full.melt(id_vars=["Model Configuration", "Model Link"], var_name="Task", value_name="Score")
75
-
76
  plt.figure(figsize=(14, 10))
77
  for model in df_full["Model Configuration"]:
78
  model_data = df_full_melted[df_full_melted["Model Configuration"] == model]
79
  plt.plot(model_data["Task"], model_data["Score"], marker="o", label=model)
80
-
81
  plt.title("Performance of All Models Across Tasks", fontsize=16)
82
  plt.xlabel("Task", fontsize=14)
83
  plt.ylabel("Score", fontsize=14)
@@ -85,21 +77,13 @@ def plot_task_performance():
85
  plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=9)
86
  plt.grid(axis='y', linestyle='--', alpha=0.7)
87
  plt.tight_layout()
88
-
89
- img_buffer = io.BytesIO()
90
- plt.savefig(img_buffer, format='png')
91
- img_buffer.seek(0)
92
- img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
93
- plt.close()
94
- pil_image = Image.open(BytesIO(base64.b64decode(img_base64)))
95
- return pil_image, "task_performance.png"
96
 
 
97
  def plot_task_specific_top_models():
98
  top_models = df_full.iloc[:, 2:].idxmax()
99
  top_scores = df_full.iloc[:, 2:].max()
100
-
101
  results = pd.DataFrame({"Top Model": top_models, "Score": top_scores}).reset_index().rename(columns={"index": "Task"})
102
-
103
  plt.figure(figsize=(12, 6))
104
  plt.bar(results["Task"], results["Score"])
105
  plt.title("Task-Specific Top Models", fontsize=16)
@@ -107,179 +91,32 @@ def plot_task_specific_top_models():
107
  plt.ylabel("Score", fontsize=14)
108
  plt.grid(axis="y", linestyle="--", alpha=0.7)
109
  plt.tight_layout()
 
110
 
111
- img_buffer = io.BytesIO()
112
- plt.savefig(img_buffer, format='png')
113
- img_buffer.seek(0)
114
- img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
115
- plt.close()
116
- pil_image = Image.open(BytesIO(base64.b64decode(img_base64)))
117
- return pil_image, "task_specific_top_models.png"
118
-
119
  def scrape_mergekit_config(model_name):
120
- """
121
- Scrapes the Hugging Face model page for YAML configuration.
122
- """
123
  model_link = df_full.loc[df_full["Model Configuration"] == model_name, "Model Link"].values[0]
124
  response = requests.get(model_link)
125
  if response.status_code != 200:
126
  return f"Failed to fetch model page for {model_name}. Please check the link."
127
-
128
  soup = BeautifulSoup(response.text, "html.parser")
129
- yaml_config = soup.find("pre") # Assume YAML is in <pre> tags
130
- if yaml_config:
131
- return yaml_config.text.strip()
132
- return f"No YAML configuration found for {model_name}."
133
 
 
134
  def plot_heatmap():
135
  plt.figure(figsize=(12, 8))
136
  sns.heatmap(df_full.iloc[:, 2:], annot=True, cmap="YlGnBu", xticklabels=columns[2:], yticklabels=df_full["Model Configuration"])
137
  plt.title("Performance Heatmap", fontsize=16)
138
  plt.tight_layout()
139
-
140
- img_buffer = io.BytesIO()
141
- plt.savefig(img_buffer, format='png')
142
- img_buffer.seek(0)
143
- img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
144
- plt.close()
145
- pil_image = Image.open(BytesIO(base64.b64decode(img_base64)))
146
- return pil_image, "performance_heatmap.png"
147
-
148
-
149
- def download_yaml(yaml_content, model_name):
150
- """
151
- Generates a downloadable link for the scraped YAML content.
152
- """
153
- if "No YAML configuration found" in yaml_content or "Failed to fetch model page" in yaml_content:
154
- return None # Do not return a link if there's no config or a fetch error
155
-
156
- filename = f"{model_name.replace('/', '_')}_config.yaml"
157
- return gr.File(value=yaml_content.encode(), filename=filename)
158
-
159
- def download_all_data():
160
- # Prepare data to download
161
- csv_buffer = io.StringIO()
162
- df_full.to_csv(csv_buffer, index=False)
163
- csv_data = csv_buffer.getvalue().encode('utf-8')
164
-
165
- # Prepare all plots
166
- average_plot_pil, average_plot_name = plot_average_scores()
167
- task_plot_pil, task_plot_name = plot_task_performance()
168
- top_models_plot_pil, top_models_plot_name = plot_task_specific_top_models()
169
- heatmap_plot_pil, heatmap_plot_name = plot_heatmap()
170
-
171
- plot_dict = {
172
- "average_performance": (average_plot_pil, average_plot_name),
173
- "task_performance": (task_plot_pil, task_plot_name),
174
- "top_models": (top_models_plot_pil, top_models_plot_name),
175
- "heatmap": (heatmap_plot_pil, heatmap_plot_name)
176
- }
177
 
178
- zip_buffer = io.BytesIO()
179
- with zipfile.ZipFile(zip_buffer, 'w') as zf:
180
- zf.writestr("model_scores.csv", csv_data)
181
-
182
- for name, (pil_image, filename) in plot_dict.items():
183
- image_bytes = io.BytesIO()
184
- pil_image.save(image_bytes, format='PNG')
185
- image_bytes.seek(0)
186
- zf.writestr(filename, image_bytes.read())
187
-
188
-
189
- for model_name in df_full["Model Configuration"].to_list():
190
- yaml_content = scrape_mergekit_config(model_name)
191
- if "No YAML configuration found" not in yaml_content and "Failed to fetch model page" not in yaml_content:
192
- zf.writestr(f"{model_name.replace('/', '_')}_config.yaml", yaml_content.encode())
193
-
194
- zip_buffer.seek(0)
195
-
196
- return zip_buffer, "analysis_data.zip"
197
-
198
- def scrape_model_page(model_url):
199
- """
200
- Scrapes the Hugging Face model page for YAML configuration and other details.
201
- """
202
- try:
203
- # Fetch the model page
204
- response = requests.get(model_url)
205
- if response.status_code != 200:
206
- return f"Error: Unable to fetch the page (Status Code: {response.status_code})"
207
-
208
- soup = BeautifulSoup(response.text, "html.parser")
209
-
210
- # Extract YAML configuration (usually inside <pre> tags)
211
- yaml_config = soup.find("pre")
212
- yaml_text = yaml_config.text.strip() if yaml_config else "No YAML configuration found."
213
-
214
- # Extract additional metadata or performance (if available)
215
- metadata_section = soup.find("div", class_="metadata")
216
- metadata_text = metadata_section.text.strip() if metadata_section else "No metadata found."
217
-
218
- # Return the scraped details
219
- return f"**YAML Configuration:**\n{yaml_text}\n\n**Metadata:**\n{metadata_text}"
220
-
221
- except Exception as e:
222
- return f"Error: {str(e)}"
223
-
224
- def display_scraped_model_data(model_url):
225
- """
226
- Displays YAML configuration and metadata for a given model URL.
227
- """
228
- return scrape_model_page(model_url)
229
-
230
-
231
- # Gradio app
232
  with gr.Blocks() as demo:
233
- gr.Markdown("# Comprehensive Model Performance Analysis with Hugging Face Links")
234
-
235
- with gr.Row():
236
- btn1 = gr.Button("Show Average Performance")
237
- img1 = gr.Image(type="pil", label="Average Performance Plot")
238
- img1_download = gr.File(label="Download Average Performance")
239
- btn1.click(plot_average_scores, outputs=[img1,img1_download])
240
-
241
- with gr.Row():
242
- btn2 = gr.Button("Show Task Performance")
243
- img2 = gr.Image(type="pil", label="Task Performance Plot")
244
- img2_download = gr.File(label="Download Task Performance")
245
- btn2.click(plot_task_performance, outputs=[img2, img2_download])
246
-
247
- with gr.Row():
248
- btn3 = gr.Button("Task-Specific Top Models")
249
- img3 = gr.Image(type="pil", label="Task-Specific Top Models Plot")
250
- img3_download = gr.File(label="Download Top Models")
251
- btn3.click(plot_task_specific_top_models, outputs=[img3, img3_download])
252
-
253
- with gr.Row():
254
- btn4 = gr.Button("Plot Performance Heatmap")
255
- heatmap_img = gr.Image(type="pil", label="Performance Heatmap")
256
- heatmap_download = gr.File(label="Download Heatmap")
257
- btn4.click(plot_heatmap, outputs=[heatmap_img, heatmap_download])
258
-
259
- with gr.Row():
260
- model_selector = gr.Dropdown(choices=df_full["Model Configuration"].tolist(), label="Select a Model")
261
- with gr.Column():
262
- scrape_btn = gr.Button("Scrape MergeKit Configuration")
263
- yaml_output = gr.Textbox(lines=10, placeholder="YAML Configuration will appear here.")
264
- scrape_btn.click(scrape_mergekit_config, inputs=model_selector, outputs=yaml_output)
265
- with gr.Column():
266
- save_yaml_btn = gr.Button("Save MergeKit Configuration")
267
- yaml_download = gr.File(label="Download MergeKit Configuration")
268
- save_yaml_btn.click(download_yaml, inputs=[yaml_output, model_selector], outputs=yaml_download)
269
-
270
-
271
- with gr.Row():
272
- download_all_btn = gr.Button("Download Everything")
273
- all_downloads = gr.File(label="Download All Data")
274
- download_all_btn.click(download_all_data, outputs=all_downloads)
275
-
276
- # Live scraping feature
277
- gr.Markdown("## Live Scraping Features")
278
- with gr.Row():
279
- url_input = gr.Textbox(label="Enter Hugging Face Model URL", placeholder="https://huggingface.co/<model>")
280
- live_scrape_btn = gr.Button("Scrape Model Page")
281
- live_scrape_output = gr.Textbox(label="Scraped Data", lines=15)
282
- live_scrape_btn.click(display_scraped_model_data, inputs=url_input, outputs=live_scrape_output)
283
-
284
-
285
- demo.launch()
 
1
+
2
+ ## Comprehensive Model Performance Analysis
3
+
4
+ ### Importing Required Libraries
5
  import pandas as pd
6
  import matplotlib.pyplot as plt
7
  import seaborn as sns
 
15
  from PIL import Image
16
  from io import BytesIO
17
 
18
+ ### Input Data
19
+ # Data with links to Hugging Face repositories
20
  data_full = [
21
  ['CultriX/Qwen2.5-14B-SLERPv7', 'https://huggingface.co/CultriX/Qwen2.5-14B-SLERPv7', 0.7205, 0.8272, 0.7541, 0.6581, 0.5, 0.729],
22
  ['djuna/Q2.5-Veltha-14B-0.5', 'https://huggingface.co/djuna/Q2.5-Veltha-14B-0.5', 0.7492, 0.8386, 0.7305, 0.598, 0.43, 0.7817],
 
44
  ['CultriX/Qwen2.5-14B-Wernickev7', 'https://huggingface.co/CultriX/Qwen2.5-14B-Wernickev7', 0.7147, 0.7599, 0.6097, 0.7056, 0.57, 0.7164],
45
  ['CultriX/Qwen2.5-14B-FinalMerge-tmp2', 'https://huggingface.co/CultriX/Qwen2.5-14B-FinalMerge-tmp2', 0.7255, 0.8192, 0.7535, 0.6671, 0.5, 0.7612],
46
  ]
 
47
  columns = ["Model Configuration", "Model Link", "tinyArc", "tinyHellaswag", "tinyMMLU", "tinyTruthfulQA", "tinyTruthfulQA_mc1", "tinyWinogrande"]
 
 
48
  df_full = pd.DataFrame(data_full, columns=columns)
49
 
50
+ ### Visualization and Analytics Functions
51
+
52
+ # 1. Plot Average Scores
53
  def plot_average_scores():
54
  df_full["Average Score"] = df_full.iloc[:, 2:].mean(axis=1)
55
  df_avg_sorted = df_full.sort_values(by="Average Score", ascending=False)
 
56
  plt.figure(figsize=(12, 8))
57
  plt.barh(df_avg_sorted["Model Configuration"], df_avg_sorted["Average Score"])
58
  plt.title("Average Performance of Models Across Tasks", fontsize=16)
 
61
  plt.gca().invert_yaxis()
62
  plt.grid(axis='x', linestyle='--', alpha=0.7)
63
  plt.tight_layout()
64
+ plt.show()
 
 
 
 
 
 
 
 
 
65
 
66
+ # 2. Plot Task Performance
67
  def plot_task_performance():
68
  df_full_melted = df_full.melt(id_vars=["Model Configuration", "Model Link"], var_name="Task", value_name="Score")
 
69
  plt.figure(figsize=(14, 10))
70
  for model in df_full["Model Configuration"]:
71
  model_data = df_full_melted[df_full_melted["Model Configuration"] == model]
72
  plt.plot(model_data["Task"], model_data["Score"], marker="o", label=model)
 
73
  plt.title("Performance of All Models Across Tasks", fontsize=16)
74
  plt.xlabel("Task", fontsize=14)
75
  plt.ylabel("Score", fontsize=14)
 
77
  plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=9)
78
  plt.grid(axis='y', linestyle='--', alpha=0.7)
79
  plt.tight_layout()
80
+ plt.show()
 
 
 
 
 
 
 
81
 
82
+ # 3. Plot Task-Specific Top Models
83
  def plot_task_specific_top_models():
84
  top_models = df_full.iloc[:, 2:].idxmax()
85
  top_scores = df_full.iloc[:, 2:].max()
 
86
  results = pd.DataFrame({"Top Model": top_models, "Score": top_scores}).reset_index().rename(columns={"index": "Task"})
 
87
  plt.figure(figsize=(12, 6))
88
  plt.bar(results["Task"], results["Score"])
89
  plt.title("Task-Specific Top Models", fontsize=16)
 
91
  plt.ylabel("Score", fontsize=14)
92
  plt.grid(axis="y", linestyle="--", alpha=0.7)
93
  plt.tight_layout()
94
+ plt.show()
95
 
96
+ ### YAML Configuration and Scraping Utilities
97
+ # 1. Scrape MergeKit Configuration
 
 
 
 
 
 
98
  def scrape_mergekit_config(model_name):
 
 
 
99
  model_link = df_full.loc[df_full["Model Configuration"] == model_name, "Model Link"].values[0]
100
  response = requests.get(model_link)
101
  if response.status_code != 200:
102
  return f"Failed to fetch model page for {model_name}. Please check the link."
 
103
  soup = BeautifulSoup(response.text, "html.parser")
104
+ yaml_config = soup.find("pre")
105
+ return yaml_config.text.strip() if yaml_config else f"No YAML configuration found for {model_name}."
 
 
106
 
107
+ ### Performance Heatmap
108
  def plot_heatmap():
109
  plt.figure(figsize=(12, 8))
110
  sns.heatmap(df_full.iloc[:, 2:], annot=True, cmap="YlGnBu", xticklabels=columns[2:], yticklabels=df_full["Model Configuration"])
111
  plt.title("Performance Heatmap", fontsize=16)
112
  plt.tight_layout()
113
+ plt.show()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
+ ### Gradio App
116
+ # Building the Interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  with gr.Blocks() as demo:
118
+ gr.Markdown("# Comprehensive Model Performance Analysis")
119
+ gr.Image(type="pil", label="Average Performance Plot")
120
+ gr.Image(type="pil", label="Task Performance Plot")
121
+ gr.Image(type="pil", label="Task-Specific Top Models")
122
+ demo.launch()