File size: 2,074 Bytes
8e8a9fc 749d1d8 8e8a9fc 749d1d8 fc00c85 8f11653 8e8a9fc 749d1d8 46a475d 92b7bbd 749d1d8 8f11653 fc00c85 8f11653 fc00c85 749d1d8 |
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 |
import os
from pathlib import Path
import gradio as gr
from rich.console import Console
from rich.syntax import Syntax
proj_dir = Path(__name__).parent
subreddit = os.environ["SUBREDDIT"]
username = os.environ["USERNAME"]
dataset_name = f"{username}/dataset-creator-{subreddit}"
with open(proj_dir / "media/reddit_scraper.drawio.html", "r") as f:
html_string = f.read()
html_string.replace("SPACE_NAME", f"{username}/reddit-dataset-creator")
html_string.replace("SPACE_LINK", f"https://huggingface.co/spaces/{username}/reddit-dataset-creator")
html_string.replace("DATASET_NAME", f"{username}/dataset-creator-{subreddit}")
html_string.replace("DATASET_LINK", f"https://huggingface.co/datasets/{username}/dataset-creator-{subreddit}")
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)",
# )
markdown = f"""
# Reddit Scraper
This is a reddit scraper which builds [{dataset_name}](https://huggingface.co/datasets/{dataset_name}).
See the diagram below:
{html_string}
"""
with gr.Blocks() as demo:
name = gr.Markdown(markdown)
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.launch(server_name="0.0.0.0", show_error=True, server_port=7860, enable_queue=True)
|