Spaces:
Running
Running
File size: 2,416 Bytes
158554b |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
import logging
from functools import partial
from io import StringIO
import gradio as gr
from apscheduler.schedulers.background import BackgroundScheduler
from bs4 import BeautifulSoup
from rich.console import Console
from rich.syntax import Syntax
from src.backend import backend_routine
from src.logging import configure_root_logger, log_file, setup_logger
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("numexpr").setLevel(logging.WARNING)
logging.getLogger("absl").setLevel(logging.WARNING)
configure_root_logger()
logging.basicConfig(level=logging.INFO)
logger = setup_logger(__name__)
def log_file_to_html_string(reverse=True):
with open(log_file, "rt") as f:
lines = f.readlines()
lines = lines[-300:]
if reverse:
lines = reversed(lines)
output = "".join(lines)
syntax = Syntax(output, "python", theme="monokai", word_wrap=True)
console = Console(record=True, width=150, style="#272822", file=StringIO())
console.print(syntax)
html_content = console.export_html(inline_styles=True)
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(html_content, "lxml")
# Modify the <pre> tag and add custom styles
pre_tag = soup.pre
pre_tag["class"] = "scrollable"
del pre_tag["style"]
# Add your custom styles and the .scrollable CSS to the <style> tag
style_tag = soup.style
style_tag.append(
"""
pre, code {
background-color: #272822;
}
.scrollable {
font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace;
height: 500px;
overflow: auto;
}
"""
)
return soup.prettify()
REPO_ID = "open-rl-leaderboard/leaderboard"
RESULTS_REPO = "open-rl-leaderboard/results"
links_md = f"""
# Important links
| Description | Link |
|-----------------|------|
| Leaderboard | [{REPO_ID}](https://huggingface.co/spaces/{REPO_ID}) |
| Results Repo | [{RESULTS_REPO}](https://huggingface.co/datasets/{RESULTS_REPO}) |
"""
with gr.Blocks() as demo:
gr.Markdown(links_md)
gr.HTML(partial(log_file_to_html_string), every=1)
with gr.Row():
gr.DownloadButton("Download Log File", value=log_file)
scheduler = BackgroundScheduler()
scheduler.add_job(func=backend_routine, trigger="interval", seconds=5 * 60, max_instances=1)
scheduler.start()
if __name__ == "__main__":
demo.queue().launch()
|