Files
auracaster-webui/frontend.py

175 lines
7.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 = [
{
"name": "Gate1",
"endpoints": ["endpoint1", "endpoint2"],
"languages": DEFAULT_LANGUAGES.copy()
},
{
"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["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}"
)
# 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 {i+1}",
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_{i}" 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"):
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()