CultriX commited on
Commit
a2b3402
·
verified ·
1 Parent(s): c581f25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +205 -9
app.py CHANGED
@@ -4,8 +4,15 @@ import seaborn as sns
4
  import gradio as gr
5
  import requests
6
  from bs4 import BeautifulSoup
 
 
 
 
 
 
7
 
8
- # Local dataset (optional, for pre-loaded data)
 
9
  data_full = [
10
  ['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],
11
  ['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],
@@ -35,8 +42,159 @@ data_full = [
35
  ]
36
 
37
  columns = ["Model Configuration", "Model Link", "tinyArc", "tinyHellaswag", "tinyMMLU", "tinyTruthfulQA", "tinyTruthfulQA_mc1", "tinyWinogrande"]
 
 
38
  df_full = pd.DataFrame(data_full, columns=columns)
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  def scrape_model_page(model_url):
41
  """
42
  Scrapes the Hugging Face model page for YAML configuration and other details.
@@ -69,21 +227,59 @@ def display_scraped_model_data(model_url):
69
  """
70
  return scrape_model_page(model_url)
71
 
 
 
72
  with gr.Blocks() as demo:
73
- gr.Markdown("# Model Performance Analysis with Live Scraping")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
- # Pre-loaded dataset features
76
  with gr.Row():
77
- btn1 = gr.Button("Show Summary Statistics")
78
- stats_output = gr.Dataframe()
79
- btn1.click(lambda: df_full.describe().T, outputs=stats_output)
 
 
 
 
 
 
 
80
 
 
 
 
 
 
81
  # Live scraping feature
82
  gr.Markdown("## Live Scraping Features")
83
  with gr.Row():
84
  url_input = gr.Textbox(label="Enter Hugging Face Model URL", placeholder="https://huggingface.co/<model>")
85
- scrape_btn = gr.Button("Scrape Model Page")
86
- scrape_output = gr.Textbox(label="Scraped Data", lines=15)
87
- scrape_btn.click(display_scraped_model_data, inputs=url_input, outputs=scrape_output)
 
88
 
89
  demo.launch()
 
4
  import gradio as gr
5
  import requests
6
  from bs4 import BeautifulSoup
7
+ import io
8
+ import os
9
+ import base64
10
+ 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],
 
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)
57
+ plt.xlabel("Average Score", fontsize=14)
58
+ plt.ylabel("Model Configuration", fontsize=14)
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)
84
+ plt.xticks(rotation=45)
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)
106
+ plt.xlabel("Task", fontsize=14)
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.
 
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()