CoolFace
Apppublic

EmbodiedAgentInterface/backend

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
log_visualizer.py41 linesDownload Raw Back to display
1from io import StringIO2from pathlib import Path3 4from bs4 import BeautifulSoup5from rich.console import Console6from rich.syntax import Syntax7 8from src.display.css_html_js import style_content9from src.envs import NUM_LINES_VISUALIZE10from src.logging import log_file11 12 13def log_file_to_html_string(reverse=True):14    with open(log_file, "rt") as f:15            lines = f.readlines()16            lines = lines[-NUM_LINES_VISUALIZE:]17 18    if reverse:19        lines = reversed(lines)20 21    output = "".join(lines)22    syntax = Syntax(output, "python", theme="monokai", word_wrap=True)23 24    console = Console(record=True, width=150, style="#272822", file=StringIO())25    console.print(syntax)26    html_content = console.export_html(inline_styles=True)27 28    # Parse the HTML content using BeautifulSoup29    soup = BeautifulSoup(html_content, 'lxml')30 31    # Modify the <pre> tag and add custom styles32    pre_tag = soup.pre33    pre_tag['class'] = 'scrollable'34    del pre_tag['style']35 36    # Add your custom styles and the .scrollable CSS to the <style> tag37    style_tag = soup.style38    style_tag.append(style_content)39 40    return soup.prettify()41