Download src/streamlit_app.py from HarizalD/SPACE: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/spaces/HarizalD/SPACE/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/HarizalD/SPACE/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/HarizalD/SPACE/resolve/main/src/streamlit_app.py
2.7 kB
| import pandas as pd | |
| import streamlit as st | |
| def login(): | |
| st.title("π Login Sistem") | |
| username = st.text_input("Username") | |
| password = st.text_input("Password", type="password") | |
| if st.button("Login"): | |
| if username == "admin" and password == "1234": | |
| st.session_state["login"] = True | |
| st.success("Login berhasil β ") | |
| else: | |
| st.error("Username atau Password salah!") | |
| def dashboard(): | |
| st.title("π Dashboard Space Management - Sports & Health") | |
| # Data awal | |
| if "data" not in st.session_state: | |
| st.session_state["data"] = pd.DataFrame({ | |
| "ID": [1, 2, 3], | |
| "Nama File": ["Laporan_A.xlsx", "Proposal_B.docx", "Data_C.csv"], | |
| "Status": ["Menunggu", "Menunggu", "Menunggu"] | |
| }) | |
| # Sidebar menu | |
| st.sidebar.title("βοΈ Menu") | |
| if st.sidebar.button("πͺ Logout"): | |
| st.session_state["login"] = False | |
| st.experimental_rerun() | |
| # Upload file baru | |
| st.sidebar.header("π€ Upload File Baru") | |
| uploaded_file = st.sidebar.file_uploader("Upload Excel/CSV", type=["csv", "xlsx"]) | |
| if uploaded_file: | |
| try: | |
| if uploaded_file.name.endswith(".csv"): | |
| df_new = pd.read_csv(uploaded_file) | |
| else: | |
| df_new = pd.read_excel(uploaded_file) | |
| st.session_state["data"] = df_new | |
| st.success("File berhasil diupload dan ditampilkan!") | |
| except Exception as e: | |
| st.error(f"Gagal membaca file: {e}") | |
| # Tabel data | |
| st.subheader("π Master Data") | |
| st.dataframe(st.session_state["data"]) | |
| # Update status | |
| pilihan = st.selectbox("Pilih File untuk Approve/Tolak", | |
| st.session_state["data"]["Nama File"]) | |
| aksi = st.radio("Aksi", ["Setujui", "Tolak"]) | |
| if st.button("Update Status"): | |
| idx = st.session_state["data"].index[ | |
| st.session_state["data"]["Nama File"] == pilihan | |
| ][0] | |
| st.session_state["data"].at[idx, "Status"] = aksi | |
| st.success(f"File '{pilihan}' berhasil diupdate menjadi {aksi}") | |
| # Ringkasan data | |
| st.subheader("π Ringkasan") | |
| summary = st.session_state["data"]["Status"].value_counts() | |
| st.bar_chart(summary) | |
| # Download data | |
| st.sidebar.header("π₯ Download Data") | |
| csv = st.session_state["data"].to_csv(index=False).encode("utf-8") | |
| st.sidebar.download_button( | |
| label="Download CSV", | |
| data=csv, | |
| file_name="master_data.csv", | |
| mime="text/csv" | |
| ) | |
| # --- Main --- | |
| if "login" not in st.session_state: | |
| st.session_state["login"] = False | |
| if st.session_state["login"]: | |
| dashboard() | |
| else: | |
| login() | |