Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,9 @@ import seaborn as sns
|
|
4 |
import gradio as gr
|
5 |
import requests
|
6 |
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
7 |
|
8 |
# Input data with links to Hugging Face repositories
|
9 |
data_full = [
|
@@ -52,8 +55,14 @@ def plot_average_scores():
|
|
52 |
plt.gca().invert_yaxis()
|
53 |
plt.grid(axis='x', linestyle='--', alpha=0.7)
|
54 |
plt.tight_layout()
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
def plot_task_performance():
|
59 |
df_full_melted = df_full.melt(id_vars=["Model Configuration", "Model Link"], var_name="Task", value_name="Score")
|
@@ -70,8 +79,13 @@ def plot_task_performance():
|
|
70 |
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=9)
|
71 |
plt.grid(axis='y', linestyle='--', alpha=0.7)
|
72 |
plt.tight_layout()
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
def plot_task_specific_top_models():
|
77 |
top_models = df_full.iloc[:, 2:].idxmax()
|
@@ -86,8 +100,13 @@ def plot_task_specific_top_models():
|
|
86 |
plt.ylabel("Score", fontsize=14)
|
87 |
plt.grid(axis="y", linestyle="--", alpha=0.7)
|
88 |
plt.tight_layout()
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
def scrape_mergekit_config(model_name):
|
93 |
"""
|
@@ -109,8 +128,62 @@ def plot_heatmap():
|
|
109 |
sns.heatmap(df_full.iloc[:, 2:], annot=True, cmap="YlGnBu", xticklabels=columns[2:], yticklabels=df_full["Model Configuration"])
|
110 |
plt.title("Performance Heatmap", fontsize=16)
|
111 |
plt.tight_layout()
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
# Gradio app
|
116 |
with gr.Blocks() as demo:
|
@@ -118,28 +191,44 @@ with gr.Blocks() as demo:
|
|
118 |
|
119 |
with gr.Row():
|
120 |
btn1 = gr.Button("Show Average Performance")
|
121 |
-
img1 = gr.Image(type="
|
122 |
-
|
123 |
-
|
|
|
124 |
with gr.Row():
|
125 |
btn2 = gr.Button("Show Task Performance")
|
126 |
-
img2 = gr.Image(type="
|
127 |
-
|
|
|
128 |
|
129 |
with gr.Row():
|
130 |
btn3 = gr.Button("Task-Specific Top Models")
|
131 |
-
img3 = gr.Image(type="
|
132 |
-
|
133 |
-
|
|
|
134 |
with gr.Row():
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
138 |
|
139 |
with gr.Row():
|
140 |
model_selector = gr.Dropdown(choices=df_full["Model Configuration"].tolist(), label="Select a Model")
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
-
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 |
|
11 |
# Input data with links to Hugging Face repositories
|
12 |
data_full = [
|
|
|
55 |
plt.gca().invert_yaxis()
|
56 |
plt.grid(axis='x', linestyle='--', alpha=0.7)
|
57 |
plt.tight_layout()
|
58 |
+
|
59 |
+
img_buffer = io.BytesIO()
|
60 |
+
plt.savefig(img_buffer, format='png')
|
61 |
+
img_buffer.seek(0)
|
62 |
+
img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
|
63 |
+
plt.close()
|
64 |
+
return img_base64, "average_performance.png"
|
65 |
+
|
66 |
|
67 |
def plot_task_performance():
|
68 |
df_full_melted = df_full.melt(id_vars=["Model Configuration", "Model Link"], var_name="Task", value_name="Score")
|
|
|
79 |
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=9)
|
80 |
plt.grid(axis='y', linestyle='--', alpha=0.7)
|
81 |
plt.tight_layout()
|
82 |
+
|
83 |
+
img_buffer = io.BytesIO()
|
84 |
+
plt.savefig(img_buffer, format='png')
|
85 |
+
img_buffer.seek(0)
|
86 |
+
img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
|
87 |
+
plt.close()
|
88 |
+
return img_base64, "task_performance.png"
|
89 |
|
90 |
def plot_task_specific_top_models():
|
91 |
top_models = df_full.iloc[:, 2:].idxmax()
|
|
|
100 |
plt.ylabel("Score", fontsize=14)
|
101 |
plt.grid(axis="y", linestyle="--", alpha=0.7)
|
102 |
plt.tight_layout()
|
103 |
+
|
104 |
+
img_buffer = io.BytesIO()
|
105 |
+
plt.savefig(img_buffer, format='png')
|
106 |
+
img_buffer.seek(0)
|
107 |
+
img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
|
108 |
+
plt.close()
|
109 |
+
return img_base64, "task_specific_top_models.png"
|
110 |
|
111 |
def scrape_mergekit_config(model_name):
|
112 |
"""
|
|
|
128 |
sns.heatmap(df_full.iloc[:, 2:], annot=True, cmap="YlGnBu", xticklabels=columns[2:], yticklabels=df_full["Model Configuration"])
|
129 |
plt.title("Performance Heatmap", fontsize=16)
|
130 |
plt.tight_layout()
|
131 |
+
|
132 |
+
img_buffer = io.BytesIO()
|
133 |
+
plt.savefig(img_buffer, format='png')
|
134 |
+
img_buffer.seek(0)
|
135 |
+
img_base64 = base64.b64encode(img_buffer.read()).decode('utf-8')
|
136 |
+
plt.close()
|
137 |
+
return img_base64, "performance_heatmap.png"
|
138 |
+
|
139 |
+
|
140 |
+
def download_yaml(yaml_content, model_name):
|
141 |
+
"""
|
142 |
+
Generates a downloadable link for the scraped YAML content.
|
143 |
+
"""
|
144 |
+
if "No YAML configuration found" in yaml_content or "Failed to fetch model page" in yaml_content:
|
145 |
+
return None # Do not return a link if there's no config or a fetch error
|
146 |
+
|
147 |
+
filename = f"{model_name.replace('/', '_')}_config.yaml"
|
148 |
+
return gr.File(value=yaml_content.encode(), filename=filename)
|
149 |
+
|
150 |
+
def download_all_data():
|
151 |
+
# Prepare data to download
|
152 |
+
csv_buffer = io.StringIO()
|
153 |
+
df_full.to_csv(csv_buffer, index=False)
|
154 |
+
csv_data = csv_buffer.getvalue().encode('utf-8')
|
155 |
+
|
156 |
+
# Prepare all plots
|
157 |
+
average_plot_b64, average_plot_name = plot_average_scores()
|
158 |
+
task_plot_b64, task_plot_name = plot_task_performance()
|
159 |
+
top_models_plot_b64, top_models_plot_name = plot_task_specific_top_models()
|
160 |
+
heatmap_plot_b64, heatmap_plot_name = plot_heatmap()
|
161 |
+
|
162 |
+
plot_dict = {
|
163 |
+
"average_performance": (average_plot_b64, average_plot_name),
|
164 |
+
"task_performance": (task_plot_b64, task_plot_name),
|
165 |
+
"top_models": (top_models_plot_b64, top_models_plot_name),
|
166 |
+
"heatmap": (heatmap_plot_b64, heatmap_plot_name)
|
167 |
+
}
|
168 |
+
|
169 |
+
zip_buffer = io.BytesIO()
|
170 |
+
import zipfile
|
171 |
+
with zipfile.ZipFile(zip_buffer, 'w') as zf:
|
172 |
+
zf.writestr("model_scores.csv", csv_data)
|
173 |
+
|
174 |
+
for name, (b64, filename) in plot_dict.items():
|
175 |
+
img_data = base64.b64decode(b64)
|
176 |
+
zf.writestr(filename, img_data)
|
177 |
+
|
178 |
+
for model_name in df_full["Model Configuration"].to_list():
|
179 |
+
yaml_content = scrape_mergekit_config(model_name)
|
180 |
+
if "No YAML configuration found" not in yaml_content and "Failed to fetch model page" not in yaml_content:
|
181 |
+
zf.writestr(f"{model_name.replace('/', '_')}_config.yaml", yaml_content.encode())
|
182 |
+
|
183 |
+
zip_buffer.seek(0)
|
184 |
+
|
185 |
+
return zip_buffer, "analysis_data.zip"
|
186 |
+
|
187 |
|
188 |
# Gradio app
|
189 |
with gr.Blocks() as demo:
|
|
|
191 |
|
192 |
with gr.Row():
|
193 |
btn1 = gr.Button("Show Average Performance")
|
194 |
+
img1 = gr.Image(type="bytes", label="Average Performance Plot")
|
195 |
+
img1_download = gr.File(label="Download Average Performance")
|
196 |
+
btn1.click(plot_average_scores, outputs=[img1,img1_download])
|
197 |
+
|
198 |
with gr.Row():
|
199 |
btn2 = gr.Button("Show Task Performance")
|
200 |
+
img2 = gr.Image(type="bytes", label="Task Performance Plot")
|
201 |
+
img2_download = gr.File(label="Download Task Performance")
|
202 |
+
btn2.click(plot_task_performance, outputs=[img2, img2_download])
|
203 |
|
204 |
with gr.Row():
|
205 |
btn3 = gr.Button("Task-Specific Top Models")
|
206 |
+
img3 = gr.Image(type="bytes", label="Task-Specific Top Models Plot")
|
207 |
+
img3_download = gr.File(label="Download Top Models")
|
208 |
+
btn3.click(plot_task_specific_top_models, outputs=[img3, img3_download])
|
209 |
+
|
210 |
with gr.Row():
|
211 |
+
btn4 = gr.Button("Plot Performance Heatmap")
|
212 |
+
heatmap_img = gr.Image(type="bytes", label="Performance Heatmap")
|
213 |
+
heatmap_download = gr.File(label="Download Heatmap")
|
214 |
+
btn4.click(plot_heatmap, outputs=[heatmap_img, heatmap_download])
|
215 |
|
216 |
with gr.Row():
|
217 |
model_selector = gr.Dropdown(choices=df_full["Model Configuration"].tolist(), label="Select a Model")
|
218 |
+
with gr.Column():
|
219 |
+
scrape_btn = gr.Button("Scrape MergeKit Configuration")
|
220 |
+
yaml_output = gr.Textbox(lines=10, placeholder="YAML Configuration will appear here.")
|
221 |
+
scrape_btn.click(scrape_mergekit_config, inputs=model_selector, outputs=yaml_output)
|
222 |
+
with gr.Column():
|
223 |
+
save_yaml_btn = gr.Button("Save MergeKit Configuration")
|
224 |
+
yaml_download = gr.File(label="Download MergeKit Configuration")
|
225 |
+
save_yaml_btn.click(download_yaml, inputs=[yaml_output, model_selector], outputs=yaml_download)
|
226 |
+
|
227 |
+
|
228 |
+
with gr.Row():
|
229 |
+
download_all_btn = gr.Button("Download Everything")
|
230 |
+
all_downloads = gr.File(label="Download All Data")
|
231 |
+
download_all_btn.click(download_all_data, outputs=all_downloads)
|
232 |
+
|
233 |
|
234 |
+
demo.launch()
|