import re with open('app.py', 'r') as f: content = f.read() new_css = """def inject_css(): st.markdown(''' ''', unsafe_allow_html=True)""" # replace the inject_css function content = re.sub(r'def inject_css\(\):.*?(?=def render_dashboard\(\):)', new_css + '\n\n', content, flags=re.DOTALL) # Inline style fixes (convert #fff to var(--box-bg), #000 to var(--border)) # We be careful not to break standard valid strings content = content.replace("background-color: {('var(--high)' if high_risk_count > 0 else '#fff')};", "background-color: {('var(--high)' if high_risk_count > 0 else 'var(--box-bg)')};") # Fix inline styles for progress bars and metric cards content = content.replace('background: #fff; height: 12px; border: 2px solid #000;', 'background: var(--box-bg); height: 12px; border: 2px solid var(--border);') content = content.replace('background: #000; width:', 'background: var(--text); width:') content = content.replace('border: 2px solid #000;', 'border: 2px solid var(--border);') content = content.replace('background: #fff; border: 2px solid #000; box-shadow: 4px 4px 0px 0px #000;', 'background: var(--box-bg); border: 2px solid var(--border); box-shadow: 4px 4px 0px 0px var(--border);') content = content.replace('border-bottom: 2px solid #000;', 'border-bottom: 2px solid var(--border);') # Matplotlib styles (use dark grey colors to show up well on both if needed, but #ebebeb and #fff are used for ax) # Matplotlib does not natively support CSS variables. We will just let matplotlib maintain its light theme design, it's an image. # We will just change text color for selectbox and app dark mode. with open('app.py', 'w') as f: f.write(content)