derek-thomas's picture
derek-thomas HF staff
to set it to 'always dark' theme (#1)
8f11653
raw
history blame
1.46 kB
import gradio as gr
from rich.console import Console
from rich.syntax import Syntax
def log_file_to_html_string():
log_file = "mylog.log"
console = Console(record=True, width=150)
with open(log_file, "rt") as f:
syntax = Syntax(f.read(), "python", theme="monokai", word_wrap=True)
console.print(syntax)
html_content = console.export_html(inline_styles=True)
return html_content
#theme = gr.themes.Default().set(
# body_background_fill="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
# body_background_fill_dark="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
# )
with gr.Blocks() as demo:
name = gr.Markdown("# Reddit Scraper")
output = gr.HTML(log_file_to_html_string, every=1)
demo.load(None,
_js="""
() => {
document.body.classList.toggle('dark');
document.querySelector('gradio-app').style.backgroundColor = 'var(--color-background-primary)'
}
""",)
if __name__ == '__main__':
demo.load(None,
_js="""
() => {
document.body.classList.toggle('dark');
document.querySelector('gradio-app').style.backgroundColor = 'var(--color-background-primary)'
}
""")
demo.launch(server_name="0.0.0.0", show_error=True, server_port=7860, enable_queue=True)