File size: 1,810 Bytes
7bffaaf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import importlib
import re
from pathlib import Path

import streamlit as st
import yaml

REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r](.*)", re.DOTALL)


def render_preview(image, title, description):
    with st.container():
        image_col, text_col = st.columns((1, 4))
        with image_col:
            st.image(image)

        with text_col:
            st.subheader(title)
            st.write(description)


def render_page(post_path: Path):
    mod = importlib.import_module(str(post_path))
    mod.run_article()


def get_page_data(post_path: Path):
    mod = importlib.import_module(str(post_path))
    return {
        "title": mod.title,
        "description": mod.description,
        "date": mod.date,
        "thumbnail": mod.thumbnail,
    }


def main():
    st.set_page_config(layout="wide")
    posts = {
        "posts.welcome": "Welcome",
        "posts.context": "Hate Speech in ACM",
        "posts.dataset_exploration": "ACM Datasets",
        "posts.model_exploration": "ACM Models",
        "posts.conclusion": "Key Takeaways",
    }
    page_to_show = list(posts.keys())[0]
    with st.sidebar:

        st.markdown(
            """
            <div align="center">
                <h1>Task Exploration: Hate Speech Detection</h1>
            </div>
        """,
            unsafe_allow_html=True,
        )
        st.markdown("---")

        page_to_show = st.selectbox(
            "Navigation menu:",
            posts,
            format_func=lambda x:posts[x],
        )

        for post in posts:
            data = get_page_data(Path(post))
            clicked = render_preview(
                data.get("thumbnail"), data.get("title"), data.get("description")
            )

    if page_to_show:
        render_page(Path(page_to_show))


main()