burtenshaw commited on
Commit
4ce52ca
1 Parent(s): a1a8d26

add total progress for submissions

Browse files
Files changed (1) hide show
  1. app.py +74 -63
app.py CHANGED
@@ -12,6 +12,7 @@ client = rg.Argilla(
12
  api_key=os.getenv("ARGILLA_API_KEY"),
13
  )
14
 
 
15
  def get_progress(dataset: rg.Dataset) -> dict:
16
  dataset_progress = dataset.progress(with_users_distribution=True)
17
 
@@ -23,35 +24,40 @@ def get_progress(dataset: rg.Dataset) -> dict:
23
  "annotated": completed,
24
  "progress": progress,
25
  "users": {
26
- username: user_progress["completed"].get("submitted") + user_progress["pending"].get("submitted")
 
27
  for username, user_progress in dataset_progress["users"].items()
28
- }
29
  }
30
 
31
 
32
  def create_progress_bar(progress):
33
- top_labels = ['Completed', 'Pending']
34
 
35
- colors = ['rgba(38, 24, 74, 0.8)', 'rgba(190, 192, 213, 1)']
36
 
37
- x_data = [[progress["annotated"], progress["total"] - progress["annotated"]]]
 
 
38
 
39
- y_data = ['Progress']
40
 
41
  fig = go.Figure()
42
 
43
  for i in range(0, len(x_data[0])):
44
  for xd, yd in zip(x_data, y_data):
45
- fig.add_trace(go.Bar(
46
- x=[xd[i]], y=[yd],
47
- orientation='h',
48
- marker=dict(
49
- color=colors[i],
50
- line=dict(color='rgb(248, 248, 249)', width=1)
51
- ),
52
- hoverinfo='text',
53
- hovertext=f"{top_labels[i]} records: {xd[i]}"
54
- ))
 
 
55
 
56
  fig.update_layout(
57
  xaxis=dict(
@@ -59,59 +65,73 @@ def create_progress_bar(progress):
59
  showline=False,
60
  showticklabels=False,
61
  zeroline=False,
62
- domain=[0.15, 1]
63
-
64
  ),
65
  yaxis=dict(
66
  showgrid=False,
67
  showline=False,
68
  showticklabels=False,
69
  zeroline=False,
70
- domain=[0.15, 0.5]
71
  ),
72
- barmode='stack',
73
- paper_bgcolor='rgb(248, 248, 255)',
74
- plot_bgcolor='rgb(248, 248, 255)',
75
  margin=dict(l=120, r=10, t=140, b=80),
76
- showlegend=False
77
  )
78
 
79
  annotations = []
80
 
81
  for yd, xd in zip(y_data, x_data):
82
  # labeling the y-axis
83
- annotations.append(dict(xref='paper', yref='y',
84
- x=0.14, y=yd,
85
- xanchor='right',
86
- text=str(yd),
87
- font=dict(family='Arial', size=14,
88
- color='rgb(67, 67, 67)'),
89
- showarrow=False, align='right'))
 
 
 
 
 
 
90
  # labeling the first percentage of each bar (x_axis)
91
  if xd[0] > 0:
92
- annotations.append(dict(xref='x', yref='y',
93
- x=xd[0] / 2, y=yd,
94
- text=str(xd[0]),
95
- font=dict(family='Arial', size=14,
96
- color='rgb(248, 248, 255)'),
97
- showarrow=False))
 
 
 
 
 
98
  space = xd[0]
99
  for i in range(1, len(xd)):
100
  if xd[i] > 0:
101
  # labeling the rest of percentages for each bar (x_axis)
102
- annotations.append(dict(xref='x', yref='y',
103
- x=space + (xd[i]/2), y=yd,
104
- text=str(xd[i]),
105
- font=dict(family='Arial', size=14,
106
- color='rgb(248, 248, 255)'),
107
- showarrow=False))
 
 
 
 
 
108
  space += xd[i]
109
 
110
- fig.update_layout(annotations=annotations, height=80)
111
  return fig
112
 
113
 
114
-
115
  def create_piechart(user_annotations):
116
  sorted_users = sorted(user_annotations.items(), key=lambda x: x[1], reverse=True)
117
 
@@ -121,30 +141,28 @@ def create_piechart(user_annotations):
121
  labels.append(user)
122
  values.append(contribution)
123
 
124
- fig = go.Figure(
125
- go.Pie(
126
- labels=labels,
127
- values=values
128
- )
129
- )
130
 
131
  fig.update_layout(
132
  title_text="User contributions",
133
  height=500,
134
  margin=dict(l=10, r=10, t=50, b=10),
135
- template="ggplot2"
136
  )
137
- fig.update_traces(textposition='inside', textinfo='percent+label')
138
 
139
  return fig
140
 
 
141
  def get_datasets(client: rg.Argilla) -> List[rg.Dataset]:
142
  return client.datasets.list()
143
 
 
144
  datasets = get_datasets(client)
145
 
146
  from typing import Optional
147
 
 
148
  def update_dashboard(dataset_idx: Optional[int] = None):
149
  if dataset_idx is None:
150
  return [None, None, None]
@@ -166,16 +184,12 @@ def update_dashboard(dataset_idx: Optional[int] = None):
166
  return progress_bar, piechart, leaderboard_df
167
 
168
 
169
-
170
  with gr.Blocks() as demo:
171
  gr.Markdown("# Argilla Progress Dashboard")
172
 
173
  dataset_choices = [(dataset.name, idx) for idx, dataset in enumerate(datasets)]
174
  datasets_dropdown = gr.Dropdown(
175
- choices=dataset_choices,
176
- label="Select your dataset",
177
- value=0,
178
- visible=True
179
  )
180
 
181
  def set_selected_dataset(dataset_idx) -> None:
@@ -184,16 +198,13 @@ with gr.Blocks() as demo:
184
  dataset = datasets[dataset_idx]
185
  selected_dataset = dataset
186
 
187
-
188
  with gr.Row():
189
  progress_bar_output = gr.Plot(label="Overall Progress")
190
 
191
  gr.Markdown("## Contributor Leaderboard")
192
 
193
  with gr.Row():
194
- leaderboard_output = gr.Dataframe(
195
- headers=["User", "Submitted records"]
196
- )
197
  piechart_output = gr.Plot(label="User contributions")
198
 
199
  demo.load(
@@ -201,12 +212,12 @@ with gr.Blocks() as demo:
201
  inputs=[datasets_dropdown],
202
  outputs=[progress_bar_output, piechart_output, leaderboard_output],
203
  )
204
-
205
  demo.load(
206
  update_dashboard,
207
  inputs=[datasets_dropdown],
208
  outputs=[progress_bar_output, piechart_output, leaderboard_output],
209
- every=60,
210
  )
211
 
212
  datasets_dropdown.change(
 
12
  api_key=os.getenv("ARGILLA_API_KEY"),
13
  )
14
 
15
+
16
  def get_progress(dataset: rg.Dataset) -> dict:
17
  dataset_progress = dataset.progress(with_users_distribution=True)
18
 
 
24
  "annotated": completed,
25
  "progress": progress,
26
  "users": {
27
+ username: user_progress["completed"].get("submitted")
28
+ + user_progress["pending"].get("submitted")
29
  for username, user_progress in dataset_progress["users"].items()
30
+ },
31
  }
32
 
33
 
34
  def create_progress_bar(progress):
35
+ top_labels = ["Completed", "Pending"]
36
 
37
+ colors = ["rgba(38, 24, 74, 0.8)", "rgba(190, 192, 213, 1)"]
38
 
39
+ n_labelled_records = sum(progress["users"].values())
40
+ n_target_records = 10000
41
+ x_data = [[n_labelled_records, n_target_records - n_labelled_records]]
42
 
43
+ y_data = ["Progress"]
44
 
45
  fig = go.Figure()
46
 
47
  for i in range(0, len(x_data[0])):
48
  for xd, yd in zip(x_data, y_data):
49
+ fig.add_trace(
50
+ go.Bar(
51
+ x=[xd[i]],
52
+ y=[yd],
53
+ orientation="h",
54
+ marker=dict(
55
+ color=colors[i], line=dict(color="rgb(248, 248, 249)", width=1)
56
+ ),
57
+ hoverinfo="text",
58
+ hovertext=f"{top_labels[i]} records: {xd[i]}",
59
+ )
60
+ )
61
 
62
  fig.update_layout(
63
  xaxis=dict(
 
65
  showline=False,
66
  showticklabels=False,
67
  zeroline=False,
68
+ domain=[0.15, 1],
 
69
  ),
70
  yaxis=dict(
71
  showgrid=False,
72
  showline=False,
73
  showticklabels=False,
74
  zeroline=False,
75
+ domain=[0.15, 0.5],
76
  ),
77
+ barmode="stack",
78
+ paper_bgcolor="rgb(248, 248, 255)",
79
+ plot_bgcolor="rgb(248, 248, 255)",
80
  margin=dict(l=120, r=10, t=140, b=80),
81
+ showlegend=False,
82
  )
83
 
84
  annotations = []
85
 
86
  for yd, xd in zip(y_data, x_data):
87
  # labeling the y-axis
88
+ annotations.append(
89
+ dict(
90
+ xref="paper",
91
+ yref="y",
92
+ x=0.14,
93
+ y=yd,
94
+ xanchor="right",
95
+ text=str(yd),
96
+ font=dict(family="Arial", size=14, color="rgb(67, 67, 67)"),
97
+ showarrow=False,
98
+ align="right",
99
+ )
100
+ )
101
  # labeling the first percentage of each bar (x_axis)
102
  if xd[0] > 0:
103
+ annotations.append(
104
+ dict(
105
+ xref="x",
106
+ yref="y",
107
+ x=xd[0] / 2,
108
+ y=yd,
109
+ text=str(xd[0]),
110
+ font=dict(family="Arial", size=14, color="rgb(248, 248, 255)"),
111
+ showarrow=False,
112
+ )
113
+ )
114
  space = xd[0]
115
  for i in range(1, len(xd)):
116
  if xd[i] > 0:
117
  # labeling the rest of percentages for each bar (x_axis)
118
+ annotations.append(
119
+ dict(
120
+ xref="x",
121
+ yref="y",
122
+ x=space + (xd[i] / 2),
123
+ y=yd,
124
+ text=str(xd[i]),
125
+ font=dict(family="Arial", size=14, color="rgb(248, 248, 255)"),
126
+ showarrow=False,
127
+ )
128
+ )
129
  space += xd[i]
130
 
131
+ fig.update_layout(annotations=annotations, height=80)
132
  return fig
133
 
134
 
 
135
  def create_piechart(user_annotations):
136
  sorted_users = sorted(user_annotations.items(), key=lambda x: x[1], reverse=True)
137
 
 
141
  labels.append(user)
142
  values.append(contribution)
143
 
144
+ fig = go.Figure(go.Pie(labels=labels, values=values))
 
 
 
 
 
145
 
146
  fig.update_layout(
147
  title_text="User contributions",
148
  height=500,
149
  margin=dict(l=10, r=10, t=50, b=10),
150
+ template="ggplot2",
151
  )
152
+ fig.update_traces(textposition="inside", textinfo="percent+label")
153
 
154
  return fig
155
 
156
+
157
  def get_datasets(client: rg.Argilla) -> List[rg.Dataset]:
158
  return client.datasets.list()
159
 
160
+
161
  datasets = get_datasets(client)
162
 
163
  from typing import Optional
164
 
165
+
166
  def update_dashboard(dataset_idx: Optional[int] = None):
167
  if dataset_idx is None:
168
  return [None, None, None]
 
184
  return progress_bar, piechart, leaderboard_df
185
 
186
 
 
187
  with gr.Blocks() as demo:
188
  gr.Markdown("# Argilla Progress Dashboard")
189
 
190
  dataset_choices = [(dataset.name, idx) for idx, dataset in enumerate(datasets)]
191
  datasets_dropdown = gr.Dropdown(
192
+ choices=dataset_choices, label="Select your dataset", value=0, visible=True
 
 
 
193
  )
194
 
195
  def set_selected_dataset(dataset_idx) -> None:
 
198
  dataset = datasets[dataset_idx]
199
  selected_dataset = dataset
200
 
 
201
  with gr.Row():
202
  progress_bar_output = gr.Plot(label="Overall Progress")
203
 
204
  gr.Markdown("## Contributor Leaderboard")
205
 
206
  with gr.Row():
207
+ leaderboard_output = gr.Dataframe(headers=["User", "Submitted records"])
 
 
208
  piechart_output = gr.Plot(label="User contributions")
209
 
210
  demo.load(
 
212
  inputs=[datasets_dropdown],
213
  outputs=[progress_bar_output, piechart_output, leaderboard_output],
214
  )
215
+
216
  demo.load(
217
  update_dashboard,
218
  inputs=[datasets_dropdown],
219
  outputs=[progress_bar_output, piechart_output, leaderboard_output],
220
+ # every=60,
221
  )
222
 
223
  datasets_dropdown.change(