Spaces:
Runtime error
Runtime error
add `refresh_scheduler()`
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
|
|
11 |
import gradio as gr
|
12 |
import pandas as pd
|
13 |
|
|
|
|
|
|
|
14 |
"""
|
15 |
This is the main file for the dashboard application. It contains the main function and the functions to obtain the data and create the charts.
|
16 |
It's designed as a template to recreate the dashboard for the prompt translation project of any language.
|
@@ -273,12 +276,29 @@ def get_top(N = 10) -> pd.DataFrame:
|
|
273 |
|
274 |
return obtain_top_users(user_ids_annotations, N=N)
|
275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
|
277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
update_interval_charts = 30 # seconds
|
282 |
|
283 |
# Connect to the space with rg.init()
|
284 |
rg.init(
|
@@ -289,13 +309,8 @@ def main() -> None:
|
|
289 |
# Fetch the data initially
|
290 |
fetch_data()
|
291 |
|
292 |
-
|
293 |
-
|
294 |
-
scheduler = BackgroundScheduler()
|
295 |
-
scheduler.add_job(
|
296 |
-
func=fetch_data, trigger="interval", seconds=update_interval, max_instances=1
|
297 |
-
)
|
298 |
-
scheduler.start()
|
299 |
|
300 |
# To avoid the orange border for the Gradio elements that are in constant loading
|
301 |
css = """
|
@@ -336,7 +351,6 @@ def main() -> None:
|
|
336 |
kpi_chart_submitted,
|
337 |
inputs=[],
|
338 |
outputs=[kpi_submitted_plot],
|
339 |
-
every=update_interval_charts,
|
340 |
)
|
341 |
|
342 |
kpi_remaining_plot = gr.Plot(label="Plot")
|
@@ -344,7 +358,6 @@ def main() -> None:
|
|
344 |
kpi_chart_remaining,
|
345 |
inputs=[],
|
346 |
outputs=[kpi_remaining_plot],
|
347 |
-
every=update_interval_charts,
|
348 |
)
|
349 |
|
350 |
donut_total_plot = gr.Plot(label="Plot")
|
@@ -352,7 +365,6 @@ def main() -> None:
|
|
352 |
donut_chart_total,
|
353 |
inputs=[],
|
354 |
outputs=[donut_total_plot],
|
355 |
-
every=update_interval_charts,
|
356 |
)
|
357 |
|
358 |
gr.Markdown(
|
@@ -366,7 +378,7 @@ def main() -> None:
|
|
366 |
|
367 |
kpi_hall_plot = gr.Plot(label="Plot")
|
368 |
demo.load(
|
369 |
-
kpi_chart_total_annotators, inputs=[], outputs=[kpi_hall_plot]
|
370 |
)
|
371 |
|
372 |
top_df_plot = gr.Dataframe(
|
@@ -378,9 +390,8 @@ def main() -> None:
|
|
378 |
row_count=10,
|
379 |
col_count=(2, "fixed"),
|
380 |
interactive=False,
|
381 |
-
every=update_interval,
|
382 |
)
|
383 |
-
demo.load(get_top, None, [top_df_plot]
|
384 |
|
385 |
# Launch the Gradio interface
|
386 |
demo.launch()
|
|
|
11 |
import gradio as gr
|
12 |
import pandas as pd
|
13 |
|
14 |
+
import time
|
15 |
+
from huggingface_hub import HfApi
|
16 |
+
|
17 |
"""
|
18 |
This is the main file for the dashboard application. It contains the main function and the functions to obtain the data and create the charts.
|
19 |
It's designed as a template to recreate the dashboard for the prompt translation project of any language.
|
|
|
276 |
|
277 |
return obtain_top_users(user_ids_annotations, N=N)
|
278 |
|
279 |
+
def refresh_scheduler():
|
280 |
+
|
281 |
+
# Configure your HF Token as an env variable
|
282 |
+
token = os.getenv("HF_TOKEN")
|
283 |
+
|
284 |
+
# Unique identifier for your space
|
285 |
+
space_id = "DIBT-Russian/MPEP_Dashboard"
|
286 |
|
287 |
+
hf_api = HfApi()
|
288 |
+
|
289 |
+
while True:
|
290 |
+
try:
|
291 |
+
# Restart the space
|
292 |
+
hf_api.restart_space(space_id=space_id, token=token)
|
293 |
+
print(f"Space {space_id} has been restarted.")
|
294 |
+
except Exception as e:
|
295 |
+
print(f"Failed to restart Space {space_id}: {e}")
|
296 |
+
|
297 |
+
# Wait for 10 minutes before restarting again
|
298 |
+
time.sleep(60) # 600 seconds = 10 minutes
|
299 |
|
300 |
+
|
301 |
+
def main() -> None:
|
|
|
302 |
|
303 |
# Connect to the space with rg.init()
|
304 |
rg.init(
|
|
|
309 |
# Fetch the data initially
|
310 |
fetch_data()
|
311 |
|
312 |
+
# Fetch data on a schedule
|
313 |
+
refresh_scheduler()
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
# To avoid the orange border for the Gradio elements that are in constant loading
|
316 |
css = """
|
|
|
351 |
kpi_chart_submitted,
|
352 |
inputs=[],
|
353 |
outputs=[kpi_submitted_plot],
|
|
|
354 |
)
|
355 |
|
356 |
kpi_remaining_plot = gr.Plot(label="Plot")
|
|
|
358 |
kpi_chart_remaining,
|
359 |
inputs=[],
|
360 |
outputs=[kpi_remaining_plot],
|
|
|
361 |
)
|
362 |
|
363 |
donut_total_plot = gr.Plot(label="Plot")
|
|
|
365 |
donut_chart_total,
|
366 |
inputs=[],
|
367 |
outputs=[donut_total_plot],
|
|
|
368 |
)
|
369 |
|
370 |
gr.Markdown(
|
|
|
378 |
|
379 |
kpi_hall_plot = gr.Plot(label="Plot")
|
380 |
demo.load(
|
381 |
+
kpi_chart_total_annotators, inputs=[], outputs=[kpi_hall_plot]
|
382 |
)
|
383 |
|
384 |
top_df_plot = gr.Dataframe(
|
|
|
390 |
row_count=10,
|
391 |
col_count=(2, "fixed"),
|
392 |
interactive=False,
|
|
|
393 |
)
|
394 |
+
demo.load(get_top, None, [top_df_plot])
|
395 |
|
396 |
# Launch the Gradio interface
|
397 |
demo.launch()
|