ignacioct commited on
Commit
7acbec8
β€’
2 Parent(s): 2858122 e6bc65c

Merge commit 'e6bc65cbc9756e9ee51fe7cedb716ae30a750384' into pr/4

Browse files
Files changed (1) hide show
  1. app.py +35 -17
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.
@@ -25,15 +27,30 @@ To create a new dashboard, you need several environment variables, that you can
25
  """
26
 
27
  # Translation of legends and titles
28
- ANNOTATED = 'Annotations'
29
- NUMBER_ANNOTATED = 'Total Annotations'
30
- PENDING = 'Pending'
31
 
32
  NUMBER_ANNOTATORS = "Number of annotators"
33
- NAME = 'Username'
34
- NUMBER_ANNOTATIONS = 'Number of annotations'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- CATEGORY = 'Category'
37
 
38
  def obtain_source_target_datasets() -> (
39
  Tuple[
@@ -186,9 +203,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 = (
@@ -201,14 +216,14 @@ def kpi_chart_total_annotators() -> alt.Chart:
201
  return chart
202
 
203
 
204
- def render_hub_user_link(hub_id:str) -> str:
205
  """
206
  This function returns a link to the user's profile on Hugging Face.
207
 
208
  Args:
209
  hub_id: The user's id on Hugging Face.
210
 
211
- Returns:
212
  A string with the link to the user's profile on Hugging Face.
213
  """
214
  link = f"https://huggingface.co/{hub_id}"
@@ -255,7 +270,7 @@ def fetch_data() -> None:
255
  print(f"Data fetched: {datetime.datetime.now()}")
256
 
257
 
258
- def get_top(N = 50) -> pd.DataFrame:
259
  """
260
  This function returns the top N users with the most annotations.
261
 
@@ -287,7 +302,7 @@ def main() -> None:
287
  }
288
  """
289
 
290
- with gr.Blocks(css=css) as demo:
291
  gr.Markdown(
292
  """
293
  # 🌍 [YOUR LANGUAGE] - Multilingual Prompt Evaluation Project
@@ -343,9 +358,7 @@ def main() -> None:
343
  with gr.Row():
344
 
345
  kpi_hall_plot = gr.Plot(label="Plot")
346
- demo.load(
347
- kpi_chart_total_annotators, inputs=[], outputs=[kpi_hall_plot]
348
- )
349
 
350
  top_df_plot = gr.Dataframe(
351
  headers=[NAME, NUMBER_ANNOTATIONS],
@@ -359,9 +372,14 @@ def main() -> None:
359
  )
360
  demo.load(get_top, None, [top_df_plot])
361
 
 
 
 
 
 
362
  # Launch the Gradio interface
363
  demo.launch()
364
 
365
 
366
  if __name__ == "__main__":
367
- main()
 
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.
 
27
  """
28
 
29
  # Translation of legends and titles
30
+ ANNOTATED = "Annotations"
31
+ NUMBER_ANNOTATED = "Total Annotations"
32
+ PENDING = "Pending"
33
 
34
  NUMBER_ANNOTATORS = "Number of annotators"
35
+ NAME = "Username"
36
+ NUMBER_ANNOTATIONS = "Number of annotations"
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
 
55
  def obtain_source_target_datasets() -> (
56
  Tuple[
 
203
  total_annotators = len(user_ids_annotations)
204
 
205
  # Assuming you have a DataFrame with user data, create a sample DataFrame
206
+ data = pd.DataFrame({"Category": [NUMBER_ANNOTATORS], "Value": [total_annotators]})
 
 
207
 
208
  # Create Altair chart
209
  chart = (
 
216
  return chart
217
 
218
 
219
+ def render_hub_user_link(hub_id: str) -> str:
220
  """
221
  This function returns a link to the user's profile on Hugging Face.
222
 
223
  Args:
224
  hub_id: The user's id on Hugging Face.
225
 
226
+ Returns:
227
  A string with the link to the user's profile on Hugging Face.
228
  """
229
  link = f"https://huggingface.co/{hub_id}"
 
270
  print(f"Data fetched: {datetime.datetime.now()}")
271
 
272
 
273
+ def get_top(N=50) -> pd.DataFrame:
274
  """
275
  This function returns the top N users with the most annotations.
276
 
 
302
  }
303
  """
304
 
305
+ with gr.Blocks(css=css, delete_cache=(300, 300)) as demo:
306
  gr.Markdown(
307
  """
308
  # 🌍 [YOUR LANGUAGE] - Multilingual Prompt Evaluation Project
 
358
  with gr.Row():
359
 
360
  kpi_hall_plot = gr.Plot(label="Plot")
361
+ demo.load(kpi_chart_total_annotators, inputs=[], outputs=[kpi_hall_plot])
 
 
362
 
363
  top_df_plot = gr.Dataframe(
364
  headers=[NAME, NUMBER_ANNOTATIONS],
 
372
  )
373
  demo.load(get_top, None, [top_df_plot])
374
 
375
+ # Manage background refresh
376
+ scheduler = BackgroundScheduler()
377
+ _ = scheduler.add_job(restart, "interval", minutes=30)
378
+ scheduler.start()
379
+
380
  # Launch the Gradio interface
381
  demo.launch()
382
 
383
 
384
  if __name__ == "__main__":
385
+ main()