Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,6 @@ client = rg.Argilla(
|
|
13 |
api_key=os.getenv("ARGILLA_API_KEY"),
|
14 |
)
|
15 |
|
16 |
-
global selected_dataset
|
17 |
-
selected_dataset = os.getenv("DATASET_NAME")
|
18 |
|
19 |
def get_progress(dataset: rg.Dataset) -> dict:
|
20 |
dataset_progress = dataset.progress(with_users_distribution=True)
|
@@ -24,7 +22,7 @@ def get_progress(dataset: rg.Dataset) -> dict:
|
|
24 |
|
25 |
return {
|
26 |
"total": total,
|
27 |
-
"
|
28 |
"progress": progress,
|
29 |
"users": {
|
30 |
username: user_progress["completed"].get("submitted")
|
@@ -38,7 +36,7 @@ def create_gauge_chart(progress):
|
|
38 |
go.Indicator(
|
39 |
mode="gauge+number+delta",
|
40 |
value=progress["progress"],
|
41 |
-
title={"text": "
|
42 |
delta={"reference": 100, "increasing": {"color": "RebeccaPurple"}},
|
43 |
number={"font": {"size": 40}, "valueformat": ".1f", "suffix": "%"},
|
44 |
gauge={
|
@@ -65,8 +63,8 @@ def create_gauge_chart(progress):
|
|
65 |
dict(
|
66 |
text=(
|
67 |
f"Total records: {progress['total']}<br>"
|
68 |
-
f"
|
69 |
-
f"Remaining: {progress['total'] - progress['
|
70 |
),
|
71 |
# x=0.5,
|
72 |
# y=-0.2,
|
@@ -81,7 +79,7 @@ def create_gauge_chart(progress):
|
|
81 |
fig.add_annotation(
|
82 |
text=(
|
83 |
f"Current Progress: {progress['progress']:.1f}% complete<br>"
|
84 |
-
f"({progress['
|
85 |
),
|
86 |
xref="paper",
|
87 |
yref="paper",
|
@@ -109,10 +107,10 @@ def create_treemap(user_annotations, total_records):
|
|
109 |
text.append(f"{contribution} annotations<br>{percentage:.2f}%")
|
110 |
user_colors.append(color_scale[i % len(color_scale)])
|
111 |
|
112 |
-
labels.append("
|
113 |
parents.append("")
|
114 |
values.append(total_records)
|
115 |
-
text.append(f"Total: {total_records}
|
116 |
user_colors.append("#FFFFFF")
|
117 |
|
118 |
fig = go.Figure(
|
@@ -137,19 +135,14 @@ def create_treemap(user_annotations, total_records):
|
|
137 |
|
138 |
return fig
|
139 |
|
140 |
-
def
|
141 |
-
|
142 |
-
|
143 |
-
datasets = get_datasets(client)
|
144 |
-
|
145 |
-
def update_dashboard(dataset_idx: int| None = None):
|
146 |
-
if dataset_idx is None:
|
147 |
-
return [None, None, None]
|
148 |
-
|
149 |
-
dataset = datasets[dataset_idx]
|
150 |
progress = get_progress(dataset)
|
|
|
151 |
|
152 |
gauge_chart = create_gauge_chart(progress)
|
|
|
153 |
treemap = create_treemap(progress["users"], progress["total"])
|
154 |
|
155 |
leaderboard_df = pd.DataFrame(
|
@@ -160,213 +153,23 @@ def update_dashboard(dataset_idx: int| None = None):
|
|
160 |
"Annotations", ascending=False
|
161 |
).reset_index(drop=True)
|
162 |
|
163 |
-
return gauge_chart,
|
164 |
-
|
165 |
-
|
166 |
|
167 |
with gr.Blocks() as demo:
|
168 |
-
gr.Markdown("#
|
169 |
-
|
170 |
|
171 |
with gr.Row():
|
172 |
gauge_output = gr.Plot(label="Overall Progress")
|
173 |
-
|
174 |
-
|
175 |
with gr.Row():
|
176 |
leaderboard_output = gr.Dataframe(
|
177 |
label="Leaderboard", headers=["User", "Annotations"]
|
178 |
)
|
179 |
-
|
180 |
demo.load(
|
181 |
update_dashboard,
|
182 |
-
|
183 |
-
|
184 |
-
every=5,
|
185 |
)
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
if __name__ == "__main__":
|
190 |
-
demo.launch()
|
191 |
-
# app dashboard from https://huggingface.co/spaces/davanstrien/argilla-progress/blob/main/app.py
|
192 |
-
import os
|
193 |
-
from typing import List
|
194 |
-
|
195 |
-
import argilla as rg
|
196 |
-
import gradio as gr
|
197 |
-
import pandas as pd
|
198 |
-
import plotly.colors as colors
|
199 |
-
import plotly.graph_objects as go
|
200 |
-
|
201 |
-
client = rg.Argilla(
|
202 |
-
api_url=os.getenv("ARGILLA_API_URL"),
|
203 |
-
api_key=os.getenv("ARGILLA_API_KEY"),
|
204 |
-
)
|
205 |
-
|
206 |
-
def get_progress(dataset: rg.Dataset) -> dict:
|
207 |
-
dataset_progress = dataset.progress(with_users_distribution=True)
|
208 |
-
|
209 |
-
total, completed = dataset_progress["total"], dataset_progress["completed"]
|
210 |
-
progress = (completed / total) * 100 if total > 0 else 0
|
211 |
-
|
212 |
-
return {
|
213 |
-
"total": total,
|
214 |
-
"annotated": completed,
|
215 |
-
"progress": progress,
|
216 |
-
"users": {
|
217 |
-
username: user_progress["completed"].get("submitted")
|
218 |
-
for username, user_progress in dataset_progress["users"].items()
|
219 |
-
}
|
220 |
-
}
|
221 |
-
|
222 |
-
|
223 |
-
def create_gauge_chart(progress):
|
224 |
-
fig = go.Figure(
|
225 |
-
go.Indicator(
|
226 |
-
mode="gauge+number+delta",
|
227 |
-
value=progress["progress"],
|
228 |
-
title={"text": "Dataset Annotation Progress", "font": {"size": 24}},
|
229 |
-
delta={"reference": 100, "increasing": {"color": "RebeccaPurple"}},
|
230 |
-
number={"font": {"size": 40}, "valueformat": ".1f", "suffix": "%"},
|
231 |
-
gauge={
|
232 |
-
"axis": {"range": [None, 100], "tickwidth": 1, "tickcolor": "darkblue"},
|
233 |
-
"bar": {"color": "deepskyblue"},
|
234 |
-
"bgcolor": "white",
|
235 |
-
"borderwidth": 2,
|
236 |
-
"bordercolor": "gray",
|
237 |
-
"steps": [
|
238 |
-
{"range": [0, progress["progress"]], "color": "royalblue"},
|
239 |
-
{"range": [progress["progress"], 100], "color": "lightgray"},
|
240 |
-
],
|
241 |
-
"threshold": {
|
242 |
-
"line": {"color": "red", "width": 4},
|
243 |
-
"thickness": 0.75,
|
244 |
-
"value": 100,
|
245 |
-
},
|
246 |
-
},
|
247 |
-
)
|
248 |
-
)
|
249 |
-
|
250 |
-
fig.update_layout(
|
251 |
-
annotations=[
|
252 |
-
dict(
|
253 |
-
text=(
|
254 |
-
f"Total records: {progress['total']}<br>"
|
255 |
-
f"Annotated: {progress['annotated']} ({progress['progress']:.1f}%)<br>"
|
256 |
-
f"Remaining: {progress['total'] - progress['annotated']} ({100 - progress['progress']:.1f}%)"
|
257 |
-
),
|
258 |
-
# x=0.5,
|
259 |
-
# y=-0.2,
|
260 |
-
showarrow=False,
|
261 |
-
xref="paper",
|
262 |
-
yref="paper",
|
263 |
-
font=dict(size=16),
|
264 |
-
)
|
265 |
-
],
|
266 |
-
)
|
267 |
-
|
268 |
-
fig.add_annotation(
|
269 |
-
text=(
|
270 |
-
f"Current Progress: {progress['progress']:.1f}% complete<br>"
|
271 |
-
f"({progress['annotated']} out of {progress['total']} records annotated)"
|
272 |
-
),
|
273 |
-
xref="paper",
|
274 |
-
yref="paper",
|
275 |
-
x=0.5,
|
276 |
-
y=1.1,
|
277 |
-
showarrow=False,
|
278 |
-
font=dict(size=18),
|
279 |
-
align="center",
|
280 |
-
)
|
281 |
-
|
282 |
-
return fig
|
283 |
-
|
284 |
-
|
285 |
-
def create_treemap(user_annotations, total_records):
|
286 |
-
sorted_users = sorted(user_annotations.items(), key=lambda x: x[1], reverse=True)
|
287 |
-
color_scale = colors.qualitative.Pastel + colors.qualitative.Set3
|
288 |
-
|
289 |
-
labels, parents, values, text, user_colors = [], [], [], [], []
|
290 |
-
|
291 |
-
for i, (user, contribution) in enumerate(sorted_users):
|
292 |
-
percentage = (contribution / total_records) * 100
|
293 |
-
labels.append(user)
|
294 |
-
parents.append("Annotations")
|
295 |
-
values.append(contribution)
|
296 |
-
text.append(f"{contribution} annotations<br>{percentage:.2f}%")
|
297 |
-
user_colors.append(color_scale[i % len(color_scale)])
|
298 |
-
|
299 |
-
labels.append("Annotations")
|
300 |
-
parents.append("")
|
301 |
-
values.append(total_records)
|
302 |
-
text.append(f"Total: {total_records} annotations")
|
303 |
-
user_colors.append("#FFFFFF")
|
304 |
-
|
305 |
-
fig = go.Figure(
|
306 |
-
go.Treemap(
|
307 |
-
labels=labels,
|
308 |
-
parents=parents,
|
309 |
-
values=values,
|
310 |
-
text=text,
|
311 |
-
textinfo="label+text",
|
312 |
-
hoverinfo="label+text+value",
|
313 |
-
marker=dict(colors=user_colors, line=dict(width=2)),
|
314 |
-
)
|
315 |
-
)
|
316 |
-
|
317 |
-
fig.update_layout(
|
318 |
-
title_text="User contributions to the total end dataset",
|
319 |
-
height=500,
|
320 |
-
margin=dict(l=10, r=10, t=50, b=10),
|
321 |
-
paper_bgcolor="#F0F0F0", # Light gray background
|
322 |
-
plot_bgcolor="#F0F0F0", # Light gray background
|
323 |
-
)
|
324 |
-
|
325 |
-
return fig
|
326 |
-
|
327 |
-
def get_datasets(client: rg.Argilla) -> List[rg.Dataset]:
|
328 |
-
return client.datasets.list()
|
329 |
-
|
330 |
-
datasets = get_datasets(client)
|
331 |
-
|
332 |
-
def update_dashboard(dataset: str| None = None):
|
333 |
-
dataset = selected_dataset
|
334 |
-
progress = get_progress(dataset)
|
335 |
-
|
336 |
-
gauge_chart = create_gauge_chart(progress)
|
337 |
-
treemap = create_treemap(progress["users"], progress["total"])
|
338 |
-
|
339 |
-
leaderboard_df = pd.DataFrame(
|
340 |
-
list(progress["users"].items()), columns=["User", "Annotations"]
|
341 |
-
)
|
342 |
-
|
343 |
-
leaderboard_df = leaderboard_df.sort_values(
|
344 |
-
"Annotations", ascending=False
|
345 |
-
).reset_index(drop=True)
|
346 |
-
|
347 |
-
return gauge_chart, treemap, leaderboard_df
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
with gr.Blocks() as demo:
|
352 |
-
gr.Markdown("# Argilla Dataset Dashboard")
|
353 |
-
|
354 |
-
with gr.Row():
|
355 |
-
gauge_output = gr.Plot(label="Overall Progress")
|
356 |
-
treemap_output = gr.Plot(label="User contributions")
|
357 |
-
|
358 |
-
with gr.Row():
|
359 |
-
leaderboard_output = gr.Dataframe(
|
360 |
-
label="Leaderboard", headers=["User", "Annotations"]
|
361 |
-
)
|
362 |
-
|
363 |
-
demo.load(
|
364 |
-
update_dashboard,
|
365 |
-
#inputs=[selected_dataset],
|
366 |
-
outputs=[gauge_output, treemap_output, leaderboard_output],
|
367 |
-
every=5,
|
368 |
-
)
|
369 |
-
|
370 |
-
|
371 |
if __name__ == "__main__":
|
372 |
-
demo.launch()
|
|
|
13 |
api_key=os.getenv("ARGILLA_API_KEY"),
|
14 |
)
|
15 |
|
|
|
|
|
16 |
|
17 |
def get_progress(dataset: rg.Dataset) -> dict:
|
18 |
dataset_progress = dataset.progress(with_users_distribution=True)
|
|
|
22 |
|
23 |
return {
|
24 |
"total": total,
|
25 |
+
"completed": completed,
|
26 |
"progress": progress,
|
27 |
"users": {
|
28 |
username: user_progress["completed"].get("submitted")
|
|
|
36 |
go.Indicator(
|
37 |
mode="gauge+number+delta",
|
38 |
value=progress["progress"],
|
39 |
+
title={"text": "Sprint Progress", "font": {"size": 24}},
|
40 |
delta={"reference": 100, "increasing": {"color": "RebeccaPurple"}},
|
41 |
number={"font": {"size": 40}, "valueformat": ".1f", "suffix": "%"},
|
42 |
gauge={
|
|
|
63 |
dict(
|
64 |
text=(
|
65 |
f"Total records: {progress['total']}<br>"
|
66 |
+
f"Completed: {progress['completed']} ({progress['progress']:.1f}%)<br>"
|
67 |
+
f"Remaining: {progress['total'] - progress['completed']} ({100 - progress['progress']:.1f}%)"
|
68 |
),
|
69 |
# x=0.5,
|
70 |
# y=-0.2,
|
|
|
79 |
fig.add_annotation(
|
80 |
text=(
|
81 |
f"Current Progress: {progress['progress']:.1f}% complete<br>"
|
82 |
+
f"({progress['completed']} out of {progress['total']} records completed)"
|
83 |
),
|
84 |
xref="paper",
|
85 |
yref="paper",
|
|
|
107 |
text.append(f"{contribution} annotations<br>{percentage:.2f}%")
|
108 |
user_colors.append(color_scale[i % len(color_scale)])
|
109 |
|
110 |
+
labels.append("Records")
|
111 |
parents.append("")
|
112 |
values.append(total_records)
|
113 |
+
text.append(f"Total: {total_records} records")
|
114 |
user_colors.append("#FFFFFF")
|
115 |
|
116 |
fig = go.Figure(
|
|
|
135 |
|
136 |
return fig
|
137 |
|
138 |
+
def update_dashboard():
|
139 |
+
dataset = client.datasets(name=os.getenv("DATASET_NAME"), workspace=os.getenv("WORKSPACE"))
|
140 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
progress = get_progress(dataset)
|
142 |
+
|
143 |
|
144 |
gauge_chart = create_gauge_chart(progress)
|
145 |
+
print(progress["users"])
|
146 |
treemap = create_treemap(progress["users"], progress["total"])
|
147 |
|
148 |
leaderboard_df = pd.DataFrame(
|
|
|
153 |
"Annotations", ascending=False
|
154 |
).reset_index(drop=True)
|
155 |
|
156 |
+
return gauge_chart, leaderboard_df
|
|
|
|
|
157 |
|
158 |
with gr.Blocks() as demo:
|
159 |
+
gr.Markdown("# ALRAGE (Arabic Language RAG Evaluation) Community Sprint")
|
|
|
160 |
|
161 |
with gr.Row():
|
162 |
gauge_output = gr.Plot(label="Overall Progress")
|
163 |
+
|
|
|
164 |
with gr.Row():
|
165 |
leaderboard_output = gr.Dataframe(
|
166 |
label="Leaderboard", headers=["User", "Annotations"]
|
167 |
)
|
|
|
168 |
demo.load(
|
169 |
update_dashboard,
|
170 |
+
outputs=[gauge_output, leaderboard_output],
|
171 |
+
|
|
|
172 |
)
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
if __name__ == "__main__":
|
175 |
+
demo.launch()
|