Py.Cafe

pyponcoroweline/

sk-youth-impact-portal

πŸ™οΈ SK Youth Impact Portal

DocsPricing
  • app.py
  • requirements.txt
app.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import streamlit as st
import pandas as pd

# --- PyCafe / Pyodide: Install fpdf safely ---
try:
    from fpdf import FPDF
except Exception:
    import micropip, asyncio

    async def install_fpdf():
        await micropip.install("fpdf")
        global FPDF
        from fpdf import FPDF

    asyncio.get_event_loop().create_task(install_fpdf())

# ================= SET PAGE CONFIG ==================
st.set_page_config(page_title="SK Youth Portal", layout="wide")

# ================= SESSION STATE ==================
if "user_points" not in st.session_state:
    st.session_state.user_points = 0  # starting points
if "user_name" not in st.session_state:
    st.session_state.user_name = ""  # store current user name

# ================= PAGE STYLE ==================
st.markdown("""
    <style>
    .main { background-color: #0e1117; color: white; }
    .stButton>button { border-radius: 20px; background-color: #00d4ff; color: black; font-weight: bold; }
    </style>
""", unsafe_allow_html=True)

# ================= CERTIFICATE FUNCTION ==================
def create_certificate(user_name, activity_name, points):
    pdf = FPDF(orientation='L', unit='mm', format='A4')
    pdf.add_page()

    # Certificate Background (your Canva template)
    pdf.image("cert.jpeg", x=0, y=0, w=297, h=210)  # <-- updated file name

    # Text Overlay
    pdf.set_font("Arial", 'B', 36)
    pdf.set_text_color(0, 0, 0)
    pdf.cell(0, 110, user_name, ln=True, align='C')

    pdf.set_font("Arial", '', 20)
    pdf.cell(0, -40, f"For participating in {activity_name}", ln=True, align='C')
    pdf.cell(0, 60, f"And earning {points} Leadership Points", ln=True, align='C')

    return pdf.output(dest="S").encode("latin-1")

# ================= SIDEBAR ==================
with st.sidebar:
    st.title("πŸ™οΈ SK Portal")
    page = st.radio("Navigate to:", 
                    ["Dashboard", "Activity Feed", "Evaluation & Rewards", "Certificates"])
    st.info("Log in to track your points!")

# ================= DASHBOARD PAGE ==================
if page == "Dashboard":
    st.title("πŸ† Youth Impact Leaderboard")
    st.write("Your contribution stats!")

    col1, col2 = st.columns([1,2])

    with col1:
        st.subheader("Your Stats")
        st.metric("Your Current Points",
                  f"{st.session_state.user_points} pts")
        st.progress(st.session_state.user_points / 200)  # assuming 200 pts max
        st.caption("Next Rank: Silver Badge at 100 pts")

    with col2:
        # Example leaderboard (top contributors, you dynamically get points from session)
        data = {
            "Rank": [1,2,3,4],
            "Name": ["Juan Dela Cruz","Maria Clara","You","Kiko Matsing"],
            "Points":[150,125,st.session_state.user_points,50]
        }
        st.table(pd.DataFrame(data))

# ================= ACTIVITY FEED PAGE ==================
elif page == "Activity Feed":
    st.header("πŸ“’ Recent & Upcoming Activities")
    
    col_a, col_b = st.columns(2)

    with col_a:
        st.image("https://images.unsplash.com/photo-1544928147-79a2dbc1f389?w=500",
                 caption="Coastal Cleanup")
        st.write("**Date:** Dec 15, 2025")
        if st.button("Complete Activity", key="act1"):
            st.session_state.user_points += 15
            st.success(f"Activity completed! Total points: {st.session_state.user_points}")

    with col_b:
        st.image("https://images.unsplash.com/photo-1511632765486-a01980e01a18?w=500",
                 caption="Youth Night")
        st.write("**Date:** Jan 5, 2026")
        if st.button("Complete Activity", key="act2"):
            st.session_state.user_points += 20
            st.success(f"Activity completed! Total points: {st.session_state.user_points}")

# ================= EVALUATION & REWARDS PAGE ==================
elif page == "Evaluation & Rewards":
    st.header("πŸ“ Post-Activity Evaluation")
    
    with st.form("eval_form"):
        # Get user's name once and store it in session
        if not st.session_state.user_name:
            st.session_state.user_name = st.text_input("Full Name for Certificate")

        act = st.selectbox("Which activity did you attend?", 
                           ["Coastal Cleanup","Tech Seminar"])
        rating = st.slider("Rate the activity", 1, 5)
        feedback = st.text_area("What can we improve?")
        submitted = st.form_submit_button("Submit & Claim Reward")

        if submitted:
            if st.session_state.user_name:
                st.session_state.user_points += 15
                st.success(f"Form submitted! Total points: {st.session_state.user_points}")
                st.balloons()

                cert = create_certificate(st.session_state.user_name, act, 15)
                st.download_button(
                    "πŸŽ“ Download My Certificate",
                    data=cert,
                    file_name="SK_Certificate.pdf",
                    mime="application/pdf"
                )
            else:
                st.warning("Please enter your name to generate the certificate.")

# ================= CERTIFICATE PAGE ==================
elif page == "Certificates":
    st.header("πŸŽ“ SK Digital Certificate Portal")

    name_input = st.text_input("Enter your Full Name:", st.session_state.user_name)
    if name_input:
        st.session_state.user_name = name_input

    activity = st.selectbox("Select Activity:",
                            ["Coastal Cleanup","Basketball League","Tech Seminar"])

    if st.button("Generate My Certificate"):
        if st.session_state.user_name:
            pdf_bytes = create_certificate(st.session_state.user_name, activity, st.session_state.user_points)
            st.success("Certificate Ready!")
            st.balloons()

            st.download_button(
                "⬇️ Download Certificate (PDF)",
                data=pdf_bytes,
                file_name=f"SK_Certificate_{st.session_state.user_name}.pdf",
                mime="application/pdf"
            )
        else:
            st.error("Please enter your name first!")