ZennyKenny commited on
Commit
7be166d
·
verified ·
1 Parent(s): e0b58c0

background scheduler

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -12,7 +12,7 @@ import gradio as gr
12
  import pandas as pd
13
 
14
  import time
15
- from huggingface_hub import HfApi
16
  import threading
17
 
18
  """
@@ -28,6 +28,9 @@ To create a new dashboard, you need several environment variables, that you can
28
  - ARGILLA_API_KEY: The API key to access the Huggingface Space. Please, write this as a secret in the Huggingface Space configuration.
29
  """
30
 
 
 
 
31
  # Translation of legends and titles
32
  ANNOTATED = 'Аннотации'
33
  NUMBER_ANNOTATED = 'Всего аннотаций'
@@ -39,6 +42,9 @@ NUMBER_ANNOTATIONS = 'Количество аннотаций'
39
 
40
  CATEGORY = 'Категория'
41
 
 
 
 
42
  def obtain_source_target_datasets() -> (
43
  Tuple[
44
  FeedbackDataset | RemoteFeedbackDataset, FeedbackDataset | RemoteFeedbackDataset
@@ -277,6 +283,14 @@ def get_top(N = 10) -> pd.DataFrame:
277
 
278
  return obtain_top_users(user_ids_annotations, N=N)
279
 
 
 
 
 
 
 
 
 
280
 
281
  def main() -> None:
282
 
@@ -370,6 +384,11 @@ def main() -> None:
370
  )
371
  demo.load(get_top, None, [top_df_plot])
372
 
 
 
 
 
 
373
  # Launch the Gradio interface
374
  demo.launch()
375
 
 
12
  import pandas as pd
13
 
14
  import time
15
+ from huggingface_hub import restart_space
16
  import threading
17
 
18
  """
 
28
  - ARGILLA_API_KEY: The API key to access the Huggingface Space. Please, write this as a secret in the Huggingface Space configuration.
29
  """
30
 
31
+ # Get env variable
32
+ HF_TOKEN = os.getenv("HF_TOKEN")
33
+
34
  # Translation of legends and titles
35
  ANNOTATED = 'Аннотации'
36
  NUMBER_ANNOTATED = 'Всего аннотаций'
 
42
 
43
  CATEGORY = 'Категория'
44
 
45
+ # Start scheduler timer
46
+ time_start = datetime.now()
47
+
48
  def obtain_source_target_datasets() -> (
49
  Tuple[
50
  FeedbackDataset | RemoteFeedbackDataset, FeedbackDataset | RemoteFeedbackDataset
 
283
 
284
  return obtain_top_users(user_ids_annotations, N=N)
285
 
286
+ def restart():
287
+ gr.Info("Restarting space...")
288
+ restart_space("DIBT-Russian/MPEP_Dashboard", token=HF_TOKEN)
289
+
290
+
291
+ with gr.Blocks() as demo:
292
+ gr.Markdown(f"Time started: {time_start}")
293
+
294
 
295
  def main() -> None:
296
 
 
384
  )
385
  demo.load(get_top, None, [top_df_plot])
386
 
387
+ # Manage background refresh
388
+ scheduler = BackgroundScheduler()
389
+ job = scheduler.add_job(restart, "interval", minutes=30)
390
+ scheduler.start()
391
+
392
  # Launch the Gradio interface
393
  demo.launch()
394