derek-thomas HF staff commited on
Commit
8e8a9fc
1 Parent(s): ed3130d

Adding diagram

Browse files
Files changed (2) hide show
  1. app.py +25 -1
  2. media/reddit_scraper.drawio.html +11 -0
app.py CHANGED
@@ -1,7 +1,23 @@
 
 
 
1
  import gradio as gr
2
  from rich.console import Console
3
  from rich.syntax import Syntax
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  def log_file_to_html_string():
7
  log_file = "mylog.log"
@@ -20,9 +36,17 @@ def log_file_to_html_string():
20
  # body_background_fill="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
21
  # body_background_fill_dark="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
22
  # )
 
 
 
 
 
 
 
 
23
 
24
  with gr.Blocks() as demo:
25
- name = gr.Markdown("# Reddit Scraper")
26
  output = gr.HTML(log_file_to_html_string, every=1)
27
  demo.load(None,
28
  _js="""
 
1
+ import os
2
+ from pathlib import Path
3
+
4
  import gradio as gr
5
  from rich.console import Console
6
  from rich.syntax import Syntax
7
 
8
+ proj_dir = Path(__name__).parent
9
+
10
+ subreddit = os.environ["SUBREDDIT"]
11
+ username = os.environ["USERNAME"]
12
+ dataset_name = f"{username}/dataset-creator-{subreddit}"
13
+
14
+ with open(proj_dir / "media/reddit_scraper.drawio.html", "r") as f:
15
+ html_string = f.read()
16
+ html_string.replace("SPACE_NAME", f"{username}/reddit-dataset-creator")
17
+ html_string.replace("SPACE_LINK", f"https://huggingface.co/spaces/{username}/reddit-dataset-creator")
18
+ html_string.replace("DATASET_NAME", f"{username}/dataset-creator-{subreddit}")
19
+ html_string.replace("DATASET_LINK", f"https://huggingface.co/datasets/{username}/dataset-creator-{subreddit}")
20
+
21
 
22
  def log_file_to_html_string():
23
  log_file = "mylog.log"
 
36
  # body_background_fill="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
37
  # body_background_fill_dark="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
38
  # )
39
+ markdown = f"""
40
+ # Reddit Scraper
41
+ This is a reddit scraper which builds [{dataset_name}](https://huggingface.co/datasets/{dataset_name}).
42
+
43
+ See the diagram below:
44
+
45
+ {html_string}
46
+ """
47
 
48
  with gr.Blocks() as demo:
49
+ name = gr.Markdown("")
50
  output = gr.HTML(log_file_to_html_string, every=1)
51
  demo.load(None,
52
  _js="""
media/reddit_scraper.drawio.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head>
5
+ <title>reddit_scraper</title>
6
+ <meta charset="utf-8"/>
7
+ </head>
8
+ <body><div class="mxgraph" style="max-width:100%;border:1px solid transparent;" data-mxgraph="{&quot;highlight&quot;:&quot;#0000ff&quot;,&quot;nav&quot;:true,&quot;resize&quot;:true,&quot;toolbar&quot;:&quot;zoom layers tags lightbox&quot;,&quot;edit&quot;:&quot;_blank&quot;,&quot;xml&quot;:&quot;&lt;mxfile host=\&quot;app.diagrams.net\&quot; modified=\&quot;2023-04-14T12:12:14.014Z\&quot; agent=\&quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36\&quot; etag=\&quot;puEjOIZigDmpONhGThsE\&quot; version=\&quot;21.1.7\&quot; type=\&quot;device\&quot;&gt;\n &lt;diagram name=\&quot;Page-1\&quot; id=\&quot;14ddc1Tw5ZQC4xUkB2ri\&quot;&gt;\n &lt;mxGraphModel dx=\&quot;1034\&quot; dy=\&quot;783\&quot; grid=\&quot;1\&quot; gridSize=\&quot;10\&quot; guides=\&quot;1\&quot; tooltips=\&quot;1\&quot; connect=\&quot;1\&quot; arrows=\&quot;1\&quot; fold=\&quot;1\&quot; page=\&quot;1\&quot; pageScale=\&quot;1\&quot; pageWidth=\&quot;850\&quot; pageHeight=\&quot;1100\&quot; math=\&quot;0\&quot; shadow=\&quot;0\&quot;&gt;\n &lt;root&gt;\n &lt;mxCell id=\&quot;0\&quot; /&gt;\n &lt;mxCell id=\&quot;1\&quot; parent=\&quot;0\&quot; /&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-3\&quot; value=\&quot;\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;\&quot; edge=\&quot;1\&quot; parent=\&quot;1\&quot; source=\&quot;KhBTRBst3V2Bs5u7l5Na-1\&quot; target=\&quot;KhBTRBst3V2Bs5u7l5Na-2\&quot;&gt;\n &lt;mxGeometry relative=\&quot;1\&quot; as=\&quot;geometry\&quot; /&gt;\n &lt;/mxCell&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-7\&quot; value=\&quot;HF API\&quot; style=\&quot;edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];\&quot; vertex=\&quot;1\&quot; connectable=\&quot;0\&quot; parent=\&quot;KhBTRBst3V2Bs5u7l5Na-3\&quot;&gt;\n &lt;mxGeometry x=\&quot;-0.125\&quot; y=\&quot;1\&quot; relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;mxPoint as=\&quot;offset\&quot; /&gt;\n &lt;/mxGeometry&gt;\n &lt;/mxCell&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-1\&quot; value=\&quot;HF SPACE&amp;lt;br&amp;gt;&amp;lt;a href=&amp;quot;SPACE_LINK&amp;quot;&amp;gt;SPACE_NAME&amp;lt;/a&amp;gt;\&quot; style=\&quot;rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;\&quot; vertex=\&quot;1\&quot; parent=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;340\&quot; y=\&quot;360\&quot; width=\&quot;160\&quot; height=\&quot;80\&quot; as=\&quot;geometry\&quot; /&gt;\n &lt;/mxCell&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-2\&quot; value=\&quot;HF DATASET &amp;lt;br&amp;gt;&amp;lt;a href=&amp;quot;DATASET_LINK&amp;quot;&amp;gt;DATASET_NAME&amp;lt;/a&amp;gt;\&quot; style=\&quot;rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;\&quot; vertex=\&quot;1\&quot; parent=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;110\&quot; y=\&quot;360\&quot; width=\&quot;160\&quot; height=\&quot;80\&quot; as=\&quot;geometry\&quot; /&gt;\n &lt;/mxCell&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-4\&quot; value=\&quot;&amp;lt;a href=&amp;quot;pushshift.io&amp;quot;&amp;gt;Pushshift.io&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;Hosts Reddit Data\&quot; style=\&quot;rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;\&quot; vertex=\&quot;1\&quot; parent=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;590\&quot; y=\&quot;360\&quot; width=\&quot;160\&quot; height=\&quot;80\&quot; as=\&quot;geometry\&quot; /&gt;\n &lt;/mxCell&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-8\&quot; value=\&quot;\&quot; style=\&quot;endArrow=classic;startArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;\&quot; edge=\&quot;1\&quot; parent=\&quot;1\&quot; source=\&quot;KhBTRBst3V2Bs5u7l5Na-1\&quot; target=\&quot;KhBTRBst3V2Bs5u7l5Na-4\&quot;&gt;\n &lt;mxGeometry width=\&quot;50\&quot; height=\&quot;50\&quot; relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;mxPoint x=\&quot;470\&quot; y=\&quot;530\&quot; as=\&quot;sourcePoint\&quot; /&gt;\n &lt;mxPoint x=\&quot;520\&quot; y=\&quot;480\&quot; as=\&quot;targetPoint\&quot; /&gt;\n &lt;/mxGeometry&gt;\n &lt;/mxCell&gt;\n &lt;mxCell id=\&quot;KhBTRBst3V2Bs5u7l5Na-9\&quot; value=\&quot;HTTP\&quot; style=\&quot;edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];\&quot; vertex=\&quot;1\&quot; connectable=\&quot;0\&quot; parent=\&quot;KhBTRBst3V2Bs5u7l5Na-8\&quot;&gt;\n &lt;mxGeometry x=\&quot;0.225\&quot; y=\&quot;1\&quot; relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;mxPoint x=\&quot;-9\&quot; y=\&quot;1\&quot; as=\&quot;offset\&quot; /&gt;\n &lt;/mxGeometry&gt;\n &lt;/mxCell&gt;\n &lt;/root&gt;\n &lt;/mxGraphModel&gt;\n &lt;/diagram&gt;\n&lt;/mxfile&gt;\n&quot;}"></div>
9
+ <script type="text/javascript" src="https://viewer.diagrams.net/js/viewer-static.min.js"></script>
10
+ </body>
11
+ </html>