Spaces:
Sleeping
Sleeping
Commit
·
bc7b615
1
Parent(s):
84f637a
app.py
CHANGED
@@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
|
|
5 |
import seaborn as sns
|
6 |
from scipy import stats
|
7 |
from sklearn.manifold import TSNE
|
|
|
8 |
|
9 |
unfiltered_spaces_with_outliers = pd.read_csv('hugging_face_spaces.csv')
|
10 |
spaces = unfiltered_spaces_with_outliers[unfiltered_spaces_with_outliers['likes'] >= 3]
|
@@ -83,16 +84,74 @@ def get_corr_scatter_community_interactions():
|
|
83 |
return fig
|
84 |
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
def get_top_spaces(quantity, min_value, max_value, filter_by, sort_by):
|
87 |
top_spaces = spaces[(spaces[filter_by] >= min_value) & (spaces[filter_by] <= max_value)]
|
88 |
top_spaces = top_spaces.sort_values(filter_by, ascending=True if sort_by == 'ascending' else False)
|
89 |
top_spaces = top_spaces[['repo_id', filter_by]].iloc[:quantity]
|
90 |
|
91 |
-
fig = plt.figure(figsize=(10,
|
92 |
-
|
93 |
-
plt.
|
|
|
|
|
94 |
plt.tight_layout()
|
95 |
-
return gr.Dataframe.update(value=top_spaces.astype(str).to_numpy().tolist()),
|
96 |
|
97 |
|
98 |
def change_limits(filter_by):
|
@@ -130,7 +189,7 @@ def pie_plot(data, figsize=(10, 5)):
|
|
130 |
fig = plt.figure(figsize=figsize)
|
131 |
for i, (categories, counts) in enumerate(data.items()):
|
132 |
plt.subplot(1, len(data), i+1)
|
133 |
-
plt.pie(list(map(int, counts.split(","))), colors=colors, labels=categories.split(","),
|
134 |
# draw circle
|
135 |
centre_circle = plt.Circle((0, 0), 0.70, fc='white')
|
136 |
plt.gcf().gca().add_artist(centre_circle)
|
@@ -221,7 +280,8 @@ with gr.Blocks(css="""
|
|
221 |
#md {width: 60%; padding: 0px 10px 0px}
|
222 |
#plot {width: 40%; margin: auto;}
|
223 |
#spacer {padding: 15px 15px 15px 15px}
|
224 |
-
|
|
|
225 |
gr.Markdown("""
|
226 |
# Exploring the statistics of 🤗 Spaces
|
227 |
Hugging Face Spaces offer a simple way to host ML demo apps directly on your profile or your organization’s profile. This allows you to create your ML portfolio, showcase your projects at conferences or to stakeholders, and work collaboratively with other people in the ML ecosystem.
|
@@ -298,10 +358,11 @@ with gr.Blocks(css="""
|
|
298 |
type="numpy",
|
299 |
headers=["Repo ID", 'Value'],
|
300 |
datatype=["str", "number"],
|
301 |
-
value=spaces.sort_values('likes')[['repo_id', 'likes']].iloc[:10].astype(str).to_numpy().tolist(),
|
302 |
)
|
303 |
with gr.Column():
|
304 |
-
data_plot = gr.Plot()
|
|
|
305 |
filter_by.change(fn=change_limits, inputs=[filter_by], outputs=[min_value, max_value])
|
306 |
submit.click(fn=get_top_spaces, inputs=[quantity, min_value, max_value, filter_by, sort_by], outputs=[data_points, data_plot])
|
307 |
gr.Markdown("", elem_id='spacer')
|
|
|
5 |
import seaborn as sns
|
6 |
from scipy import stats
|
7 |
from sklearn.manifold import TSNE
|
8 |
+
from test import get_plot
|
9 |
|
10 |
unfiltered_spaces_with_outliers = pd.read_csv('hugging_face_spaces.csv')
|
11 |
spaces = unfiltered_spaces_with_outliers[unfiltered_spaces_with_outliers['likes'] >= 3]
|
|
|
84 |
return fig
|
85 |
|
86 |
|
87 |
+
def circular_bar_plot():
|
88 |
+
# top_spaces = spaces[(spaces[filter_by] >= min_value) & (spaces[filter_by] <= max_value)]
|
89 |
+
# top_spaces = top_spaces.sort_values(filter_by, ascending=True if sort_by == 'ascending' else False)
|
90 |
+
# top_spaces = top_spaces[['repo_id', filter_by]].iloc[:quantity]
|
91 |
+
# labels = list("ABCDEFG")
|
92 |
+
# data = [21, 57, 88, 14, 76, 91, 26]
|
93 |
+
# fig = plt.figure(figsize=(10, 11))
|
94 |
+
# n = len(data)
|
95 |
+
# k = 10 ** int(log10(max(data)))
|
96 |
+
# m = k * (1 + max(data) // k)
|
97 |
+
# r = 1.5
|
98 |
+
# w = r / n
|
99 |
+
# colors = [cm.terrain(i / n) for i in range(n)]
|
100 |
+
# plt.axis("equal")
|
101 |
+
# for i in range(n):
|
102 |
+
# innerring, _ = plt.pie([m - data[i], data[i]], radius = r - i * w, startangle = 90, labels = ["", labels[i]], labeldistance = 1 - 1 / (1.5 * (n - i)), textprops = {"alpha": 0}, colors = ["white", colors[i]])
|
103 |
+
# plt.setp(innerring, width = w, edgecolor = "white")
|
104 |
+
#
|
105 |
+
# plt.legend()
|
106 |
+
# return fig
|
107 |
+
cathegories = ["Electronics", "Appliances", "Books", "Music", "Clothing", "Cars", "Food/Beverages", "Personal Hygiene",
|
108 |
+
"Personal Health/OTC", "Hair Care"]
|
109 |
+
percent = [81, 77, 70, 69, 69, 68, 62, 62, 61, 60]
|
110 |
+
|
111 |
+
# number of data points
|
112 |
+
n = len(percent)
|
113 |
+
# percent of circle to draw for the largest circle
|
114 |
+
percent_circle = max(percent) / 100
|
115 |
+
|
116 |
+
r = 1.5 # outer radius of the chart
|
117 |
+
r_inner = 0.4 # inner radius of the chart
|
118 |
+
# calculate width of each ring
|
119 |
+
w = (r - r_inner) / n
|
120 |
+
|
121 |
+
# create colors along a chosen colormap
|
122 |
+
#colors = [plt.cm.plasma(i / n) for i in range(n)]
|
123 |
+
colors = plt.cm.tab10.colors
|
124 |
+
|
125 |
+
# create figure, axis
|
126 |
+
fig = plt.figure(figsize=(10, 11))
|
127 |
+
plt.axis("equal")
|
128 |
+
|
129 |
+
for i in range(n):
|
130 |
+
radius = r - i * w
|
131 |
+
plt.pie([percent[i] / max(percent) * percent_circle], radius=radius, startangle=90,
|
132 |
+
counterclock=False,
|
133 |
+
colors=[colors[i]],
|
134 |
+
labels=[f'{cathegories[i]} – {percent[i]}%'], labeldistance=None,
|
135 |
+
wedgeprops={'width': w, 'edgecolor': 'white'})
|
136 |
+
plt.text(0, radius - w / 2, f'{cathegories[i]} – {percent[i]}% ', ha='right', va='center')
|
137 |
+
|
138 |
+
# plt.legend(loc='upper right', bbox_to_anchor=(0.5, 1.1), prop={'size': 12})
|
139 |
+
plt.tight_layout()
|
140 |
+
return fig
|
141 |
+
|
142 |
+
|
143 |
def get_top_spaces(quantity, min_value, max_value, filter_by, sort_by):
|
144 |
top_spaces = spaces[(spaces[filter_by] >= min_value) & (spaces[filter_by] <= max_value)]
|
145 |
top_spaces = top_spaces.sort_values(filter_by, ascending=True if sort_by == 'ascending' else False)
|
146 |
top_spaces = top_spaces[['repo_id', filter_by]].iloc[:quantity]
|
147 |
|
148 |
+
fig = plt.figure(figsize=(10, 11))
|
149 |
+
all_top_spaces = spaces.sort_values('likes', ascending=False)[['repo_id', 'likes', 'total_commits', 'community_interactions']].iloc[:100]
|
150 |
+
plt.scatter(all_top_spaces['community_interactions'], all_top_spaces['total_commits'], s=all_top_spaces['likes'])
|
151 |
+
# plt.bar(top_spaces['repo_id'], top_spaces[filter_by])
|
152 |
+
# plt.xticks(rotation=30)
|
153 |
plt.tight_layout()
|
154 |
+
return gr.Dataframe.update(value=top_spaces.astype(str).to_numpy().tolist()), fig
|
155 |
|
156 |
|
157 |
def change_limits(filter_by):
|
|
|
189 |
fig = plt.figure(figsize=figsize)
|
190 |
for i, (categories, counts) in enumerate(data.items()):
|
191 |
plt.subplot(1, len(data), i+1)
|
192 |
+
plt.pie(list(map(int, counts.split(","))), colors=colors, labels=categories.split(","), startangle=90)
|
193 |
# draw circle
|
194 |
centre_circle = plt.Circle((0, 0), 0.70, fc='white')
|
195 |
plt.gcf().gca().add_artist(centre_circle)
|
|
|
280 |
#md {width: 60%; padding: 0px 10px 0px}
|
281 |
#plot {width: 40%; margin: auto;}
|
282 |
#spacer {padding: 15px 15px 15px 15px}
|
283 |
+
#top_spaces_plot {height: 435px}
|
284 |
+
""") as demo:
|
285 |
gr.Markdown("""
|
286 |
# Exploring the statistics of 🤗 Spaces
|
287 |
Hugging Face Spaces offer a simple way to host ML demo apps directly on your profile or your organization’s profile. This allows you to create your ML portfolio, showcase your projects at conferences or to stakeholders, and work collaboratively with other people in the ML ecosystem.
|
|
|
358 |
type="numpy",
|
359 |
headers=["Repo ID", 'Value'],
|
360 |
datatype=["str", "number"],
|
361 |
+
value=spaces.sort_values('likes', ascending=False)[['repo_id', 'likes']].iloc[:10].astype(str).to_numpy().tolist(),
|
362 |
)
|
363 |
with gr.Column():
|
364 |
+
# data_plot = gr.Plot(value=get_plot(), elem_id='top_spaces_plot')
|
365 |
+
data_plot = gr.Plot(value=get_top_spaces(10, 3, spaces['likes'].max(), 'likes', 'descending')[1], elem_id='top_spaces_plot')
|
366 |
filter_by.change(fn=change_limits, inputs=[filter_by], outputs=[min_value, max_value])
|
367 |
submit.click(fn=get_top_spaces, inputs=[quantity, min_value, max_value, filter_by, sort_by], outputs=[data_points, data_plot])
|
368 |
gr.Markdown("", elem_id='spacer')
|
test.py
CHANGED
@@ -1,4 +1,79 @@
|
|
|
|
|
|
1 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import numpy as np
|
3 |
import pandas as pd
|
4 |
+
# Ensures reproducibility of random numbers
|
5 |
+
rng = np.random.default_rng(123)
|
6 |
+
# Build a dataset
|
7 |
+
# df = pd.DataFrame({
|
8 |
+
# "name": [f"item {i}" for i in range(1, 51)],
|
9 |
+
# "value": rng.integers(low=30, high=100, size=50),
|
10 |
+
# "group": ["A"] * 10 + ["B"] * 20 + ["C"] * 12 + ["D"] * 8
|
11 |
+
# })
|
12 |
|
13 |
+
unfiltered_spaces_with_outliers = pd.read_csv('hugging_face_spaces.csv')
|
14 |
+
spaces = unfiltered_spaces_with_outliers[unfiltered_spaces_with_outliers['likes'] >= 3]
|
15 |
+
df = spaces.sort_values('likes', ascending=False).iloc[1:51][['repo_id', 'likes', 'sdk']]
|
16 |
+
df['likes'] = df['likes'] / 5
|
17 |
+
df = df.sample(frac=1)
|
18 |
+
# df.to_csv('x.csv')
|
19 |
+
|
20 |
+
def get_label_rotation(angle, offset):
|
21 |
+
# Rotation must be specified in degrees :(
|
22 |
+
rotation = np.rad2deg(angle + offset)
|
23 |
+
if angle <= np.pi:
|
24 |
+
alignment = "right"
|
25 |
+
rotation = rotation + 180
|
26 |
+
else:
|
27 |
+
alignment = "left"
|
28 |
+
return rotation, alignment
|
29 |
+
|
30 |
+
|
31 |
+
def add_labels(angles, values, labels, offset, ax):
|
32 |
+
padding = 4
|
33 |
+
for angle, value, label, in zip(angles, values, labels):
|
34 |
+
angle = angle
|
35 |
+
rotation, alignment = get_label_rotation(angle, offset)
|
36 |
+
ax.text(x=angle, y=value + padding, s=label, size=11, ha=alignment, va="center", rotation=rotation, rotation_mode="anchor")
|
37 |
+
|
38 |
+
|
39 |
+
def get_plot():
|
40 |
+
ANGLES = np.linspace(0, 2 * np.pi, len(df), endpoint=False)
|
41 |
+
VALUES = df["likes"].values
|
42 |
+
LABELS = df["repo_id"].values
|
43 |
+
|
44 |
+
# Determine the width of each bar.
|
45 |
+
# The circumference is '2 * pi', so we divide that total width over the number of bars.
|
46 |
+
WIDTH = 2 * np.pi / len(VALUES)
|
47 |
+
|
48 |
+
# Determines where to place the first bar.
|
49 |
+
# By default, matplotlib starts at 0 (the first bar is horizontal)
|
50 |
+
# but here we say we want to start at pi/2 (90 deg)
|
51 |
+
OFFSET = np.pi / 2
|
52 |
+
|
53 |
+
# Initialize Figure and Axis
|
54 |
+
fig, ax = plt.subplots(figsize=(20, 22), subplot_kw={"projection": "polar"})
|
55 |
+
|
56 |
+
# Specify offset
|
57 |
+
ax.set_theta_offset(OFFSET)
|
58 |
+
|
59 |
+
# Set limits for radial (y) axis. The negative lower bound creates the whole in the middle.
|
60 |
+
ax.set_ylim(-100, df['likes'].max())
|
61 |
+
|
62 |
+
# Remove all spines
|
63 |
+
ax.set_frame_on(False)
|
64 |
+
|
65 |
+
# Remove grid and tick marks
|
66 |
+
ax.xaxis.grid(False)
|
67 |
+
ax.yaxis.grid(False)
|
68 |
+
ax.set_xticks([])
|
69 |
+
ax.set_yticks([])
|
70 |
+
|
71 |
+
# Add bars
|
72 |
+
ax.bar(
|
73 |
+
ANGLES, VALUES, width=WIDTH, linewidth=2,
|
74 |
+
color="#61a4b2", edgecolor="white"
|
75 |
+
)
|
76 |
+
|
77 |
+
# Add labels
|
78 |
+
add_labels(ANGLES, VALUES, LABELS, OFFSET, ax)
|
79 |
+
return fig
|