ignacioct commited on
Commit
18801fb
β€’
1 Parent(s): f6b736b

only fetching from the API once at load

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -30,10 +30,10 @@ def obtain_source_target_datasets() -> (
30
  filtered_source_dataset = source_dataset.filter_by(response_status=["pending"])
31
 
32
  # Obtain a list of users from the private workspace
33
- #target_dataset = rg.FeedbackDataset.from_argilla(
34
  # os.getenv("RESULTS_DATASET"), workspace=os.getenv("RESULTS_WORKSPACE")
35
- #)
36
-
37
  target_dataset = source_dataset.filter_by(response_status=["submitted"])
38
 
39
  return filtered_source_dataset, target_dataset
@@ -64,18 +64,21 @@ def get_user_annotations_dictionary(
64
 
65
  return output
66
 
 
67
  def donut_chart() -> alt.Chart:
 
68
  # Load your data
69
- source_dataset, results = obtain_source_target_datasets()
70
- annotated_records = len(results)
71
  pending_records = int(os.getenv("TARGET_RECORDS")) - annotated_records
72
 
73
  # Prepare data for the donut chart
74
- source = pd.DataFrame({
75
- "values": [annotated_records, pending_records],
76
- "category": ["Completed", "Remaining"],
77
- "colors": ["#4CAF50", "#757575"] # Green for Completed, Grey for Remaining
78
- })
 
 
79
 
80
  base = alt.Chart(source).encode(
81
  theta=alt.Theta("values:Q", stack=True),
@@ -93,6 +96,7 @@ def donut_chart() -> alt.Chart:
93
 
94
  return chart
95
 
 
96
  def kpi_chart_remaining() -> alt.Chart:
97
  """
98
  This function returns a KPI chart with the total amount of annotators.
@@ -100,8 +104,7 @@ def kpi_chart_remaining() -> alt.Chart:
100
  An altair chart with the KPI chart.
101
  """
102
 
103
- source_dataset, results = obtain_source_target_datasets()
104
- pending_records = int(os.getenv("TARGET_RECORDS")) - len(results)
105
  # Assuming you have a DataFrame with user data, create a sample DataFrame
106
  data = pd.DataFrame({"Category": ["Total remaining"], "Value": [pending_records]})
107
 
@@ -115,6 +118,7 @@ def kpi_chart_remaining() -> alt.Chart:
115
 
116
  return chart
117
 
 
118
  def kpi_chart_submitted() -> alt.Chart:
119
  """
120
  This function returns a KPI chart with the total amount of annotators.
@@ -122,9 +126,6 @@ def kpi_chart_submitted() -> alt.Chart:
122
  An altair chart with the KPI chart.
123
  """
124
 
125
- # Obtain the total amount of annotators
126
- _, target_dataset = obtain_source_target_datasets()
127
-
128
  total = len(target_dataset)
129
 
130
  # Assuming you have a DataFrame with user data, create a sample DataFrame
@@ -150,12 +151,12 @@ def kpi_chart() -> alt.Chart:
150
  """
151
 
152
  # Obtain the total amount of annotators
153
- _, target_dataset = obtain_source_target_datasets()
154
- user_ids_annotations = get_user_annotations_dictionary(target_dataset)
155
  total_annotators = len(user_ids_annotations)
156
 
157
  # Assuming you have a DataFrame with user data, create a sample DataFrame
158
- data = pd.DataFrame({"Category": ["Total Contributors"], "Value": [total_annotators]})
 
 
159
 
160
  # Create Altair chart
161
  chart = (
@@ -195,15 +196,17 @@ def main() -> None:
195
  extra_headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
196
  )
197
 
 
198
  source_dataset, target_dataset = obtain_source_target_datasets()
199
  user_ids_annotations = get_user_annotations_dictionary(target_dataset)
200
 
201
  top5_dataframe = obtain_top_5_users(user_ids_annotations)
202
 
203
- annotated = len(target_dataset)
204
  remaining = int(os.getenv("TARGET_RECORDS")) - annotated
205
- percentage_completed = round((annotated / int(os.getenv("TARGET_RECORDS"))) * 100,1)
206
-
 
207
 
208
  with gr.Blocks() as demo:
209
  gr.Markdown(
@@ -236,7 +239,6 @@ def main() -> None:
236
  outputs=[plot],
237
  )
238
 
239
-
240
  plot2 = gr.Plot(label="Plot")
241
  demo.load(
242
  donut_chart,
@@ -244,7 +246,6 @@ def main() -> None:
244
  outputs=[plot2],
245
  )
246
 
247
-
248
  gr.Markdown(
249
  """
250
  ## πŸ‘Ύ Contributors Hall of Fame
 
30
  filtered_source_dataset = source_dataset.filter_by(response_status=["pending"])
31
 
32
  # Obtain a list of users from the private workspace
33
+ # target_dataset = rg.FeedbackDataset.from_argilla(
34
  # os.getenv("RESULTS_DATASET"), workspace=os.getenv("RESULTS_WORKSPACE")
35
+ # )
36
+
37
  target_dataset = source_dataset.filter_by(response_status=["submitted"])
38
 
39
  return filtered_source_dataset, target_dataset
 
64
 
65
  return output
66
 
67
+
68
  def donut_chart() -> alt.Chart:
69
+
70
  # Load your data
71
+ annotated_records = len(target_dataset)
 
72
  pending_records = int(os.getenv("TARGET_RECORDS")) - annotated_records
73
 
74
  # Prepare data for the donut chart
75
+ source = pd.DataFrame(
76
+ {
77
+ "values": [annotated_records, pending_records],
78
+ "category": ["Completed", "Remaining"],
79
+ "colors": ["#4CAF50", "#757575"], # Green for Completed, Grey for Remaining
80
+ }
81
+ )
82
 
83
  base = alt.Chart(source).encode(
84
  theta=alt.Theta("values:Q", stack=True),
 
96
 
97
  return chart
98
 
99
+
100
  def kpi_chart_remaining() -> alt.Chart:
101
  """
102
  This function returns a KPI chart with the total amount of annotators.
 
104
  An altair chart with the KPI chart.
105
  """
106
 
107
+ pending_records = int(os.getenv("TARGET_RECORDS")) - len(target_dataset)
 
108
  # Assuming you have a DataFrame with user data, create a sample DataFrame
109
  data = pd.DataFrame({"Category": ["Total remaining"], "Value": [pending_records]})
110
 
 
118
 
119
  return chart
120
 
121
+
122
  def kpi_chart_submitted() -> alt.Chart:
123
  """
124
  This function returns a KPI chart with the total amount of annotators.
 
126
  An altair chart with the KPI chart.
127
  """
128
 
 
 
 
129
  total = len(target_dataset)
130
 
131
  # Assuming you have a DataFrame with user data, create a sample DataFrame
 
151
  """
152
 
153
  # Obtain the total amount of annotators
 
 
154
  total_annotators = len(user_ids_annotations)
155
 
156
  # Assuming you have a DataFrame with user data, create a sample DataFrame
157
+ data = pd.DataFrame(
158
+ {"Category": ["Total Contributors"], "Value": [total_annotators]}
159
+ )
160
 
161
  # Create Altair chart
162
  chart = (
 
196
  extra_headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
197
  )
198
 
199
+ global source_dataset, target_dataset, user_ids_annotations
200
  source_dataset, target_dataset = obtain_source_target_datasets()
201
  user_ids_annotations = get_user_annotations_dictionary(target_dataset)
202
 
203
  top5_dataframe = obtain_top_5_users(user_ids_annotations)
204
 
205
+ annotated = len(target_dataset)
206
  remaining = int(os.getenv("TARGET_RECORDS")) - annotated
207
+ percentage_completed = round(
208
+ (annotated / int(os.getenv("TARGET_RECORDS"))) * 100, 1
209
+ )
210
 
211
  with gr.Blocks() as demo:
212
  gr.Markdown(
 
239
  outputs=[plot],
240
  )
241
 
 
242
  plot2 = gr.Plot(label="Plot")
243
  demo.load(
244
  donut_chart,
 
246
  outputs=[plot2],
247
  )
248
 
 
249
  gr.Markdown(
250
  """
251
  ## πŸ‘Ύ Contributors Hall of Fame