import streamlit as st import uuid, io, sys def get_user_id(): if "user_id" not in st.session_state: query_params = st.query_params user_id = query_params.get("user_id", None) if not user_id: user_id = str(uuid.uuid4()) st.query_params["user_id"] = user_id st.session_state.user_id = user_id return st.session_state.user_id class StdoutRedirector(io.StringIO): def __init__(self, log_area, max_lines=20): super().__init__() self.log_area = log_area self.logs = [] self.max_lines = max_lines def write(self, message): if message.strip(): self.logs.append(message.strip()) if len(self.logs) > self.max_lines: self.logs.pop(0) self.log_area.markdown( f"