152 lines
6.0 KiB
Python
152 lines
6.0 KiB
Python
import streamlit as st
|
||
|
||
# Configuration defaults
|
||
DEFAULT_LANGUAGES = ["German", "English"]
|
||
OPTIONAL_LANGUAGES = ["French", "Spanish"]
|
||
|
||
# Initialize session state for configuration
|
||
if "endpoint_groups" not in st.session_state:
|
||
st.session_state.endpoint_groups = [
|
||
{
|
||
"name": "Gate1",
|
||
"endpoints": ["endpoint1", "endpoint2"],
|
||
"languages": DEFAULT_LANGUAGES.copy()
|
||
},
|
||
{
|
||
"name": "Gate2",
|
||
"endpoints": ["endpoint3"],
|
||
"languages": DEFAULT_LANGUAGES.copy()
|
||
}
|
||
]
|
||
|
||
from backend_model import announcement_system, AnnouncementStates
|
||
import time
|
||
|
||
def show_announcement_status():
|
||
if announcement_system.current_process.current_state != AnnouncementStates.IDLE:
|
||
status = st.status("**Airport PA System Status**", expanded=True)
|
||
|
||
with status:
|
||
# Progress elements
|
||
progress_bar = st.progress(announcement_system.current_process.progress)
|
||
time_col, stage_col = st.columns([1, 3])
|
||
|
||
# Track last displayed state
|
||
last_state = None
|
||
|
||
# Update loop
|
||
while announcement_system.current_process.current_state not in [AnnouncementStates.COMPLETE, AnnouncementStates.ERROR]:
|
||
# Update time elapsed continuously
|
||
|
||
# Only update stage display if state changed
|
||
if announcement_system.current_process.current_state != last_state:
|
||
stage_col.write(f"**Stage:** {announcement_system.current_process.current_state.value}")
|
||
#stage_col.write(f"🌐 Languages: {', '.join(announcement_system.current_process.details.languages)}")
|
||
last_state = announcement_system.current_process.current_state
|
||
time_col.write(f"⏱️ Time elapsed: {time.time() - announcement_system.current_process.details.start_time:.1f}s")
|
||
|
||
# Update progress bar
|
||
progress_bar.progress(announcement_system.current_process.progress)
|
||
time.sleep(0.3)
|
||
|
||
# Final state
|
||
if announcement_system.current_process.current_state == AnnouncementStates.ERROR:
|
||
st.error(f"❌ Error: {announcement_system.current_process.error}")
|
||
else:
|
||
st.success("✅ Announcement completed successfully")
|
||
st.write(f"📢 Announcement made to group {group['name']}:")
|
||
st.write(f"📡 Endpoints: {', '.join(group['endpoints'])}")
|
||
st.write(f"🗣️ '{announcement_system.current_process.details.text}'")
|
||
st.write(f"🌐 Languages: {', '.join(group['languages'])}")
|
||
|
||
# Reset status after completion
|
||
announcement_system.current_process.current_state = AnnouncementStates.IDLE
|
||
|
||
# Page setup
|
||
st.set_page_config(page_title="Airport Announcement System", page_icon="✈️")
|
||
|
||
# Main interface
|
||
st.title("Airport Announcement System ✈️")
|
||
|
||
# Announcements section
|
||
with st.container():
|
||
st.header("Announcements")
|
||
|
||
# Predefined announcements
|
||
col1, col2, col3 = st.columns(3)
|
||
with col1:
|
||
if st.button("Final Boarding Call"):
|
||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == "Gate1")
|
||
announcement_system.start_announcement(
|
||
"This is the final boarding call for flight LX-380 to New York",
|
||
group
|
||
)
|
||
with col2:
|
||
if st.button("Security Reminder"):
|
||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == "Gate2")
|
||
announcement_system.start_announcement(
|
||
"Please keep your luggage with you at all times",
|
||
group
|
||
)
|
||
with col3:
|
||
if st.button("Delay Notice"):
|
||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == "Gate1")
|
||
announcement_system.start_announcement(
|
||
"We regret to inform you of a 30-minute delay",
|
||
group
|
||
)
|
||
|
||
# Custom announcement
|
||
with st.form("custom_announcement"):
|
||
# Get all groups
|
||
groups = [group["name"] for group in st.session_state.endpoint_groups]
|
||
selected_group = st.selectbox("Select announcement area", groups)
|
||
message = st.text_area("Enter announcement text", "")
|
||
|
||
if st.form_submit_button("Make Announcement"):
|
||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == selected_group)
|
||
announcement_system.start_announcement(message, group)
|
||
|
||
# Configuration section in sidebar
|
||
with st.sidebar:
|
||
st.header("Configuration")
|
||
|
||
with st.expander("Endpoint Groups"):
|
||
for i, group in enumerate(st.session_state.endpoint_groups):
|
||
cols = st.columns([4, 1])
|
||
with cols[0]:
|
||
group["name"] = st.text_input(
|
||
f"Group Name {i+1}",
|
||
value=group["name"],
|
||
key=f"group_name_{i}"
|
||
)
|
||
group["endpoints"] = st.text_input(
|
||
f"Endpoints {i+1}",
|
||
value=", ".join(group["endpoints"]),
|
||
key=f"endpoints_{i}"
|
||
).split(", ")
|
||
|
||
with cols[1]:
|
||
if st.button("❌", key=f"remove_{i}"):
|
||
del st.session_state.endpoint_groups[i]
|
||
st.rerun()
|
||
|
||
group["languages"] = st.multiselect(
|
||
f"Languages {i+1}",
|
||
options=DEFAULT_LANGUAGES + OPTIONAL_LANGUAGES,
|
||
default=group["languages"],
|
||
key=f"lang_{i}"
|
||
)
|
||
st.markdown("---")
|
||
|
||
if st.button("➕ Add Group"):
|
||
st.session_state.endpoint_groups.append({
|
||
"name": f"Group {len(st.session_state.endpoint_groups)+1}",
|
||
"endpoints": [],
|
||
"languages": DEFAULT_LANGUAGES.copy()
|
||
})
|
||
|
||
# Display announcement status
|
||
st.write("---")
|
||
show_announcement_status()
|