File size: 905 Bytes
08ae6c5
 
1ffc326
9346f1c
4596a70
2a5f9fb
08ae6c5
8c49cb6
08ae6c5
b128812
2a73469
08ae6c5
 
1ffc326
b128812
1ffc326
b128812
08ae6c5
b128812
 
 
 
 
 
8c49cb6
08ae6c5
01233b7
08ae6c5
 
 
10f9b3c
08ae6c5
10f9b3c
b128812
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import logging
import subprocess
import gradio as gr
from apscheduler.schedulers.background import BackgroundScheduler

logging.basicConfig(level=logging.ERROR)

from src.logging import LOGGER, read_logs
from src.envs import API, REPO_ID

sys.stdout = LOGGER
sys.stderr = LOGGER

COUNTER = 0
def launch_backend():
    global COUNTER
    _ = subprocess.run(["python", "main_backend_lighteval.py"])
    COUNTER += 1
    # every 720 seconds = 12 hours, restart the space 
    if COUNTER == 720:
        COUNTER = 0
        API.restart_space(repo_id=REPO_ID)
    

demo = gr.Blocks()
with demo:
    logs = gr.Code(interactive=False)
    demo.load(read_logs, None, logs, every=1)
    
scheduler = BackgroundScheduler()
scheduler.add_job(launch_backend, "interval", seconds=60) # will only allow one job to be run at the same time
scheduler.start()
demo.queue(default_concurrency_limit=40).launch()