ZennyKenny commited on
Commit
1ac34dd
β€’
1 Parent(s): 8f9f16f

Add background scheduler

Browse files

Please see: https://discord.com/channels/879548962464493619/1221782765528289300

Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -17,6 +17,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.
@@ -35,6 +36,12 @@ NUMBER_ANNOTATIONS = 'Number of annotations'
35
 
36
  CATEGORY = 'Category'
37
 
 
 
 
 
 
 
38
  def obtain_source_target_datasets() -> (
39
  Tuple[
40
  FeedbackDataset | RemoteFeedbackDataset, FeedbackDataset | RemoteFeedbackDataset
@@ -359,6 +366,11 @@ def main() -> None:
359
  )
360
  demo.load(get_top, None, [top_df_plot])
361
 
 
 
 
 
 
362
  # Launch the Gradio interface
363
  demo.launch()
364
 
 
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
+ - HF_TOKEN: Token with write access from your Hugging Face account: https://huggingface.co/settings/tokens
21
  - SOURCE_DATASET: The dataset id of the source dataset
22
  - SOURCE_WORKSPACE: The workspace id of the source dataset
23
  - TARGET_RECORDS: The number of records that you have as a target to annotate. We usually set this to 500.
 
36
 
37
  CATEGORY = 'Category'
38
 
39
+ def restart():
40
+
41
+ # Update Space name with your Space information
42
+ gr.Info("Restarting space...")
43
+ restart_space("DIBT/TemplateDashboardPromptTranslation", token=HF_TOKEN)
44
+
45
  def obtain_source_target_datasets() -> (
46
  Tuple[
47
  FeedbackDataset | RemoteFeedbackDataset, FeedbackDataset | RemoteFeedbackDataset
 
366
  )
367
  demo.load(get_top, None, [top_df_plot])
368
 
369
+ # Manage background refresh
370
+ scheduler = BackgroundScheduler()
371
+ job = scheduler.add_job(restart, "interval", minutes=30)
372
+ scheduler.start()
373
+
374
  # Launch the Gradio interface
375
  demo.launch()
376