fix endpint and language selection and deletion
This commit is contained in:
@@ -4,6 +4,8 @@ from enum import Enum
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
|
ENDPOINTS = [f"endpoint{i}" for i in range(1, 4)] # Predefined endpoints
|
||||||
|
|
||||||
class AnnouncementStates(Enum):
|
class AnnouncementStates(Enum):
|
||||||
IDLE: str = "Ready"
|
IDLE: str = "Ready"
|
||||||
TRANSLATING: str = "Translating"
|
TRANSLATING: str = "Translating"
|
||||||
@@ -29,6 +31,7 @@ class AnnouncementProgress(BaseModel):
|
|||||||
|
|
||||||
class AnnouncementSystem:
|
class AnnouncementSystem:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.available_endpoints = ENDPOINTS
|
||||||
self.current_process = AnnouncementProgress(
|
self.current_process = AnnouncementProgress(
|
||||||
details=AnnouncementDetails(
|
details=AnnouncementDetails(
|
||||||
text="",
|
text="",
|
||||||
|
|||||||
41
frontend.py
41
frontend.py
@@ -1,4 +1,6 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
from backend_model import announcement_system, AnnouncementStates
|
||||||
|
import time
|
||||||
|
|
||||||
# Configuration defaults
|
# Configuration defaults
|
||||||
DEFAULT_LANGUAGES = ["German", "English"]
|
DEFAULT_LANGUAGES = ["German", "English"]
|
||||||
@@ -19,8 +21,6 @@ if "endpoint_groups" not in st.session_state:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
from backend_model import announcement_system, AnnouncementStates
|
|
||||||
import time
|
|
||||||
|
|
||||||
def show_announcement_status():
|
def show_announcement_status():
|
||||||
if announcement_system.current_process.current_state != AnnouncementStates.IDLE:
|
if announcement_system.current_process.current_state != AnnouncementStates.IDLE:
|
||||||
@@ -120,23 +120,46 @@ with st.sidebar:
|
|||||||
value=group["name"],
|
value=group["name"],
|
||||||
key=f"group_name_{i}"
|
key=f"group_name_{i}"
|
||||||
)
|
)
|
||||||
group["endpoints"] = st.text_input(
|
# 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}",
|
f"Endpoints {i+1}",
|
||||||
value=", ".join(group["endpoints"]),
|
options=announcement_system.available_endpoints,
|
||||||
key=f"endpoints_{i}"
|
default=st.session_state[f"endpoints_{i}"],
|
||||||
).split(", ")
|
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]:
|
with cols[1]:
|
||||||
if st.button("❌", key=f"remove_{i}"):
|
if st.button("❌", key=f"remove_{i}"):
|
||||||
del st.session_state.endpoint_groups[i]
|
del st.session_state.endpoint_groups[i]
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
group["languages"] = st.multiselect(
|
# 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}",
|
f"Languages {i+1}",
|
||||||
options=DEFAULT_LANGUAGES + OPTIONAL_LANGUAGES,
|
options=DEFAULT_LANGUAGES + OPTIONAL_LANGUAGES,
|
||||||
default=group["languages"],
|
default=st.session_state[f"languages_{i}"],
|
||||||
key=f"lang_{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("---")
|
st.markdown("---")
|
||||||
|
|
||||||
if st.button("➕ Add Group"):
|
if st.button("➕ Add Group"):
|
||||||
|
|||||||
Reference in New Issue
Block a user