File size: 1,768 Bytes
2ced9d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4eb6e91
2ced9d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4980059
2ced9d2
 
 
 
 
 
 
 
 
 
 
 
 
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 streamlit as st
import re
from pathlib import Path
import importlib


def render_preview(imagen, titulo, descripcion):
    with st.container():
        image_col, text_col = st.columns((1,2))
        with image_col:
            st.image(imagen)

        with text_col:
            st.subheader(titulo)
            st.write(descripcion)
            clicked = st.button("Lee más dando click aquí...", key=titulo)
        return clicked


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 {
        "titulo": mod.titulo,
        "descripcion": mod.descripcion,
        "fecha": mod.fecha,
        "thumbnail": mod.thumbnail,
    }


def main():
    st.set_page_config(layout="wide")
    posts = [
        'posts.2_private_models',
        'posts.1_blog_in_spaces'
    ]
    page_to_show = posts[0]
    with st.sidebar:
    
        st.markdown('''
            <div align="center">
                <h1>El blog de Platzi</h1>
                <p>La comunidad de Platzi en Hugging Face comparte conocimiento 🤗. Disclaimer: este es solo un ejemplo diseñado para el curso de demos en Platzi. Está basado completamente en el Tips and Tricks creado por Omar Sanseviero (https://huggingface.co/spaces/osanseviero/tips-and-tricks).</p>
        ''', unsafe_allow_html=True)
        st.markdown('---')

        for post in posts:
            data = get_page_data(Path(post))
            clicked = render_preview(data.get("thumbnail"), data.get("titulo"), data.get("descripcion"))
            if clicked:
                page_to_show = post

    if page_to_show:
        render_page(Path(page_to_show))

main()