nathaliepett commited on
Commit
8752a92
β€’
1 Parent(s): 8dbf0b0

implement dashboard changes from data-is-better-together repo

Browse files
Files changed (1) hide show
  1. app.py +37 -7
app.py CHANGED
@@ -8,6 +8,7 @@ import altair as alt
8
  import argilla as rg
9
  from argilla.feedback import FeedbackDataset
10
  from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
 
11
  import gradio as gr
12
  import pandas as pd
13
 
@@ -17,6 +18,7 @@ It's designed as a template to recreate the dashboard for the prompt translation
17
 
18
  To create a new dashboard, you need several environment variables, that you can easily set in the HuggingFace Space that you are using to host the dashboard:
19
 
 
20
  - SOURCE_DATASET: The dataset id of the source dataset
21
  - SOURCE_WORKSPACE: The workspace id of the source dataset
22
  - TARGET_RECORDS: The number of records that you have as a target to annotate. We usually set this to 500.
@@ -33,7 +35,21 @@ NUMBER_ANNOTATORS = "Anzahl der Annotierenden"
33
  NAME = 'Nutzername'
34
  NUMBER_ANNOTATIONS = 'Anzahl der Annotationen'
35
 
36
- CATEGORY = 'Kategorie'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def obtain_source_target_datasets() -> (
39
  Tuple[
@@ -108,16 +124,27 @@ def donut_chart_total() -> alt.Chart:
108
  {
109
  "values": [annotated_records, pending_records],
110
  "category": [ANNOTATED, PENDING],
111
- "colors": ["#4CAF50", "#757575"], # Green for Completed, Grey for Remaining
 
 
 
112
  }
113
  )
114
 
 
 
 
115
  base = alt.Chart(source).encode(
116
  theta=alt.Theta("values:Q", stack=True),
117
  radius=alt.Radius(
118
  "values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)
119
  ),
120
- color=alt.Color("category:N", legend=alt.Legend(title=CATEGORY)),
 
 
 
 
 
121
  )
122
 
123
  c1 = base.mark_arc(innerRadius=20, stroke="#fff")
@@ -186,9 +213,7 @@ def kpi_chart_total_annotators() -> alt.Chart:
186
  total_annotators = len(user_ids_annotations)
187
 
188
  # Assuming you have a DataFrame with user data, create a sample DataFrame
189
- data = pd.DataFrame(
190
- {"Category": [NUMBER_ANNOTATORS], "Value": [total_annotators]}
191
- )
192
 
193
  # Create Altair chart
194
  chart = (
@@ -287,7 +312,7 @@ def main() -> None:
287
  }
288
  """
289
 
290
- with gr.Blocks(css=css) as demo:
291
  gr.Markdown(
292
  """
293
  # 🌍 Deutsch - Multilingual Prompt Evaluation Project
@@ -359,6 +384,11 @@ def main() -> None:
359
  )
360
  demo.load(get_top, None, [top_df_plot])
361
 
 
 
 
 
 
362
  # Launch the Gradio interface
363
  demo.launch()
364
 
 
8
  import argilla as rg
9
  from argilla.feedback import FeedbackDataset
10
  from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
11
+ from huggingface_hub import restart_space
12
  import gradio as gr
13
  import pandas as pd
14
 
 
18
 
19
  To create a new dashboard, you need several environment variables, that you can easily set in the HuggingFace Space that you are using to host the dashboard:
20
 
21
+ - HF_TOKEN: Token with write access from your Hugging Face account: https://huggingface.co/settings/tokens
22
  - SOURCE_DATASET: The dataset id of the source dataset
23
  - SOURCE_WORKSPACE: The workspace id of the source dataset
24
  - TARGET_RECORDS: The number of records that you have as a target to annotate. We usually set this to 500.
 
35
  NAME = 'Nutzername'
36
  NUMBER_ANNOTATIONS = 'Anzahl der Annotationen'
37
 
38
+ CATEGORY = "Category"
39
+
40
+
41
+ def restart() -> None:
42
+ """
43
+ This function restarts the space where the dashboard is hosted.
44
+ """
45
+
46
+ # Update Space name with your Space information
47
+ gr.Info("Restarting space at " + str(datetime.datetime.now()))
48
+ restart_space(
49
+ "ignacioct/TryingRestartDashboard",
50
+ token=os.getenv("HF_TOKEN"),
51
+ # factory_reboot=True,
52
+ )
53
 
54
  def obtain_source_target_datasets() -> (
55
  Tuple[
 
124
  {
125
  "values": [annotated_records, pending_records],
126
  "category": [ANNOTATED, PENDING],
127
+ "colors": [
128
+ "#4682b4",
129
+ "#e68c39",
130
+ ], # Blue for Completed, Orange for Remaining
131
  }
132
  )
133
 
134
+ domain = source["category"].tolist()
135
+ range_ = source["colors"].tolist()
136
+
137
  base = alt.Chart(source).encode(
138
  theta=alt.Theta("values:Q", stack=True),
139
  radius=alt.Radius(
140
  "values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)
141
  ),
142
+ color=alt.Color(
143
+ field="category",
144
+ type="nominal",
145
+ scale=alt.Scale(domain=domain, range=range_),
146
+ legend=alt.Legend(title=CATEGORY),
147
+ ),
148
  )
149
 
150
  c1 = base.mark_arc(innerRadius=20, stroke="#fff")
 
213
  total_annotators = len(user_ids_annotations)
214
 
215
  # Assuming you have a DataFrame with user data, create a sample DataFrame
216
+ data = pd.DataFrame({"Category": [NUMBER_ANNOTATORS], "Value": [total_annotators]})
 
 
217
 
218
  # Create Altair chart
219
  chart = (
 
312
  }
313
  """
314
 
315
+ with gr.Blocks(css=css, delete_cache=(300, 300)) as demo:
316
  gr.Markdown(
317
  """
318
  # 🌍 Deutsch - Multilingual Prompt Evaluation Project
 
384
  )
385
  demo.load(get_top, None, [top_df_plot])
386
 
387
+ # Manage background refresh
388
+ scheduler = BackgroundScheduler()
389
+ _ = scheduler.add_job(restart, "interval", minutes=30)
390
+ scheduler.start()
391
+
392
  # Launch the Gradio interface
393
  demo.launch()
394