import streamlit as st from backend_model import announcement_system, AnnouncementStates import time # 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 = [ { "id": 1, "name": "Gate1", "endpoints": ["endpoint1", "endpoint2"], "languages": DEFAULT_LANGUAGES.copy() }, { "id": 2, "name": "Gate2", "endpoints": ["endpoint3"], "languages": DEFAULT_LANGUAGES.copy() } ] 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["id"] == 1) 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["id"] == 2) 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["id"] == 1) 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 with their names and IDs group_options = [(g["name"], g["id"]) for g in st.session_state.endpoint_groups] selected_group_name = st.selectbox( "Select announcement area", options=[g[0] for g in group_options] ) message = st.text_area("Enter announcement text", "") if st.form_submit_button("Make Announcement"): selected_group_id = next(g[1] for g in group_options if g[0] == selected_group_name) group = next(g for g in st.session_state.endpoint_groups if g["id"] == selected_group_id) 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]: new_name = st.text_input( f"Group Name", value=group["name"], key=f"group_name_{i}" ) if new_name != group["name"]: group["name"] = new_name st.rerun() # Initialize session state for this group's endpoints if not already set if f"endpoints_{i}" not in st.session_state: st.session_state[f"endpoints_{i}"] = group["endpoints"] # Use the multiselect with session state selected_endpoints = st.multiselect( f"Endpoints", options=announcement_system.available_endpoints, default=st.session_state[f"endpoints_{i}"], key=f"endpoints_select_{i}" ) # Update both session state and group endpoints when changed if selected_endpoints != st.session_state[f"endpoints_{i}"]: st.session_state[f"endpoints_{i}"] = selected_endpoints group["endpoints"] = selected_endpoints st.rerun() # Force immediate update with cols[1]: if st.button("❌", key=f"remove_{i}"): del st.session_state.endpoint_groups[i] st.rerun() # Initialize session state for this group's languages if not already set if f"languages" not in st.session_state: st.session_state[f"languages_{i}"] = group["languages"] # Use the multiselect with session state selected_languages = st.multiselect( f"Languages {i+1}", options=DEFAULT_LANGUAGES + OPTIONAL_LANGUAGES, default=st.session_state[f"languages_{i}"], key=f"languages_select_{i}" ) # Update both session state and group languages when changed if selected_languages != st.session_state[f"languages_{i}"]: st.session_state[f"languages_{i}"] = selected_languages group["languages"] = selected_languages st.rerun() # Force immediate update st.markdown("---") if st.button("➕ Add Group"): # Generate a unique ID for the new group new_id = max(g["id"] for g in st.session_state.endpoint_groups) + 1 if st.session_state.endpoint_groups else 1 st.session_state.endpoint_groups.append({ "id": new_id, "name": f"Group {len(st.session_state.endpoint_groups)+1}", "endpoints": [], "languages": DEFAULT_LANGUAGES.copy() }) # Display announcement status st.write("---") show_announcement_status()