Replicate the app from the image.
To upload files, please first save the app
import streamlit as st
# -------------------------------
# Validation function
# -------------------------------
def validate_fields(step):
"""Return a list of empty fields based on the step number."""
empty_fields = []
if step == 0:
if not st.session_state["name"].strip():
empty_fields.append("Nazwa")
if not st.session_state["description"].strip():
empty_fields.append("Opis")
if st.session_state["unit"] == "":
empty_fields.append("Jednostka")
if st.session_state["config"] == "":
empty_fields.append("Konfiguracja")
elif step == 1:
if not st.session_state["module"].strip():
empty_fields.append("Moduł")
if not st.session_state["nrb"].strip():
empty_fields.append("NRB klienta")
return empty_fields
# -------------------------------
# Step rendering functions
# -------------------------------
def render_step_1():
with st.expander("Krok 1 – Podstawowe informacje", expanded=True):
st.text_input("Nazwa:", key="name")
st.text_area("Opis:", key="description")
col1, col2 = st.columns(2)
with col1:
st.selectbox("Jednostka:", options=["", "Centrala"], key="unit")
with col2:
st.selectbox("Konfiguracja wyciągów", options=["", "Konfiguracja 1"], key="config")
def render_step_2():
with st.expander("Krok 2 – Dodatkowe dane", expanded=True):
st.text_input("Moduł:", key="module")
st.text_input("NRB klienta:", key="nrb")
# -------------------------------
# Main App
# -------------------------------
st.title("Kreator zakładania grupy wyciągów")
steps = [
"Krok 1 - Wpisz unikalną nazwę grupy, opis oraz wybierz formę wysyłki do klienta",
"Krok 2 - Dodaj modula lub NRB klienta"
]
# Initialize session state
if 'current_step' not in st.session_state:
st.session_state.current_step = 0
# Display step markers with highlighting for the current step
for i, step in enumerate(steps):
if i == st.session_state.current_step:
st.markdown(f"* **{step}**")
else:
st.markdown(f"* {step}", help="Not active")
# Render the appropriate step content
if st.session_state.current_step == 0:
render_step_1()
elif st.session_state.current_step == 1:
render_step_2()
# Navigation buttons
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Poprzedni Krok", disabled=st.session_state.current_step == 0):
st.session_state.current_step -= 1
st.rerun() # Rerun to refresh after changing step
with col2:
if st.button("Następny Krok", disabled=st.session_state.current_step == len(steps) - 1):
# Validate fields for the current step
empty_fields = validate_fields(st.session_state.current_step)
if empty_fields:
st.warning(f"Nieuzupełnione pola: {', '.join(empty_fields)}")
else:
st.session_state.current_step += 1
st.rerun() # Rerun to refresh after changing step
with col3:
st.button("Anuluj", type="primary")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?