Spaces:
Sleeping
Sleeping
File size: 11,235 Bytes
29ca14e 897982e 29ca14e ead2535 29ca14e ead2535 29ca14e fd50e6b 29ca14e 897982e 29ca14e 897982e 29ca14e 897982e 29ca14e 897982e 29ca14e 897982e 29ca14e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | """
F1 Predictor 2026 - Theme System
Consolidated: colors, CSS, page config, plotly helpers, team colors
"""
import streamlit as st
import streamlit.components.v1 as components
# ββ Color Palette βββββββββββββββββββββββββββββββββββββββββββ
# STRICT: skyblue, darkblue, darkgray, black, red, green ONLY
COLORS = {
"skyblue": "#3B82F6",
"skyblue_dark": "#2563EB",
"skyblue_light": "#60A5FA",
"darkblue": "#1E3A8A",
"darkgray": "#475569",
"black": "#0F172A",
"red": "#EF4444",
"green": "#10B981",
"amber": "#F59E0B",
"cyan": "#06B6D4",
"gold": "#FBBF24",
"silver": "#9CA3AF",
"bronze": "#D97706",
"bg": "#F8FAFC",
"bg_card": "#F1F5F9",
"border": "#E2E8F0",
"text": "#0F172A",
"text_secondary": "#475569",
"text_muted": "#94A3B8",
"team_red_bull": "#1E41FF",
"team_ferrari": "#DC0000",
"team_mercedes": "#00D2BE",
"team_mclaren": "#FF8000",
"team_aston_martin": "#006F62",
"team_alpine": "#0093CC",
"team_williams": "#005AFF",
"team_rb": "#2B4562",
"team_kick_sauber": "#00E701",
"team_haas": "#B6BABD",
}
TEAM_COLOR_MAP = {
"red_bull": "#1E41FF", "ferrari": "#DC0000", "mercedes": "#00D2BE",
"mclaren": "#FF8000", "aston_martin": "#006F62", "alpine": "#0093CC",
"williams": "#005AFF", "rb": "#2B4562", "kick_sauber": "#00E701",
"haas": "#B6BABD", "red bull": "#1E41FF", "aston martin": "#006F62",
"kick sauber": "#00E701", "racing bulls": "#2B4562", "sauber": "#00E701",
"visa cash app rb": "#2B4562",
}
def bar_colors_from_teams(predictions):
"""Generate bar colors based on team affiliation."""
return [TEAM_COLOR_MAP.get(
p.get("team", "").lower().strip().replace(" ", "_").replace("-", "_"),
"#3B82F6"
) for p in predictions]
def f1_plotly_layout(title="", show_legend=False):
"""Return a Plotly layout dict styled for the F1 light theme."""
return {
"paper_bgcolor": "rgba(0,0,0,0)",
"plot_bgcolor": "rgba(0,0,0,0)",
"font": {"color": "#0F172A", "family": "Inter, sans-serif"},
"title": {"text": title, "font": {"color": "#0F172A", "size": 18}},
"xaxis": {
"gridcolor": "rgba(71,85,105,0.15)", "linecolor": "rgba(71,85,105,0.3)",
"tickfont": {"color": "#475569"}, "title": {"font": {"color": "#475569"}},
},
"yaxis": {
"gridcolor": "rgba(71,85,105,0.15)", "linecolor": "rgba(71,85,105,0.3)",
"tickfont": {"color": "#475569"}, "title": {"font": {"color": "#475569"}},
},
"legend": {"font": {"color": "#475569"}, "bgcolor": "rgba(0,0,0,0)"} if show_legend else {},
"margin": {"l": 60, "r": 20, "t": 60, "b": 60},
}
# ββ Complete CSS ββββββββββββββββββββββββββββββββββββββββββ
CSS = """
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
html, body, .stApp, [data-testid="stAppViewContainer"], .main, .block-container {
background: #F8FAFC !important; background-color: #F8FAFC !important;
}
body {
font-family: 'Inter', -apple-system, sans-serif; color: #0F172A; line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
#MainMenu, header, footer, .stApp > header, [data-testid="stToolbar"] {
display: none !important;
}
/* Top Navigation Bar */
.top-nav-bar {
display: flex;
justify-content: center;
gap: 1rem;
background: #F8FAFC;
border-bottom: 1px solid #E2E8F0;
padding: 0.75rem 2rem;
position: sticky;
top: 0;
z-index: 1000;
backdrop-filter: blur(10px);
}
.nav-item {
padding: 0.5rem 1rem;
border-radius: 8px;
cursor: pointer;
font-weight: 500;
transition: all 0.2s;
color: #475569;
border: 1px solid transparent;
text-decoration: none;
display: inline-block;
}
.nav-item.active {
background: linear-gradient(135deg, #3B82F6, #2563EB);
color: #F8FAFC;
border: 1px solid #3B82F6;
}
.nav-item:hover:not(.active) {
background: #F1F5F9;
border: 1px solid #E2E8F0;
}
/* Buttons */
.stButton > button {
background: linear-gradient(135deg, #3B82F6, #2563EB) !important;
color: #F8FAFC !important; border: none !important; border-radius: 8px !important;
padding: 0.6rem 1.5rem !important; font-weight: 600 !important;
transition: all 0.2s ease !important;
}
.stButton > button:hover {
transform: translateY(-1px) !important;
box-shadow: 0 4px 12px rgba(59,130,246,0.3) !important;
}
/* Inputs */
.stSelectbox > div > div, .stNumberInput > div > div, .stSlider > div > div {
background: #F1F5F9 !important; border: 1px solid #E2E8F0 !important;
border-radius: 8px !important;
}
.stSelectbox label, .stNumberInput label, .stSlider label, .stCheckbox label {
color: #475569 !important; font-weight: 600 !important;
}
/* Metrics */
[data-testid="stMetric"] {
background: #F1F5F9 !important; border: 1px solid #E2E8F0 !important;
border-radius: 10px !important; padding: 1rem !important;
}
[data-testid="stMetric"] label { color: #94A3B8 !important; font-size: 0.75rem !important; text-transform: uppercase; letter-spacing: 0.5px; }
[data-testid="stMetric"] .css-1xarl3l { color: #0F172A !important; font-size: 1.5rem !important; font-weight: 800 !important; }
/* Tabs */
.stTabs [data-baseweb="tab-list"] {
background: #F1F5F9 !important; border-radius: 10px 10px 0 0 !important;
border-bottom: 2px solid #E2E8F0 !important;
}
.stTabs [data-baseweb="tab"] { color: #94A3B8 !important; font-weight: 500 !important; }
.stTabs [aria-selected="true"] { color: #3B82F6 !important; border-bottom: 2px solid #3B82F6 !important; }
/* DataFrames */
.stDataFrame {
background: #F1F5F9 !important; border-radius: 10px !important;
border: 1px solid #E2E8F0 !important;
}
.stDataFrame th { background: #E2E8F0 !important; color: #0F172A !important; font-weight: 700 !important; }
.stDataFrame td { color: #1E293B !important; }
.stDataFrame tr:hover td { background: #F8FAFC !important; }
/* Expanders */
.stExpander {
background: #F1F5F9 !important; border: 1px solid #E2E8F0 !important;
border-radius: 10px !important;
}
/* Sidebar */
section[data-testid="stSidebar"] {
background: #F1F5F9 !important; border-right: 1px solid #E2E8F0 !important;
}
section[data-testid="stSidebar"] .stMarkdown, section[data-testid="stSidebar"] label {
color: #0F172A !important;
}
/* Sidebar Toggle Button - POSITIONED & VISIBLE */
button[kind="icon"][data-testid="collapsedControl"],
[data-testid="collapsedControl"],
.stSidebarToggle {
background-color: #EF4444 !important;
border: 2px solid #DC2626 !important;
border-radius: 6px !important;
box-shadow: 0 2px 8px rgba(239,68,68,0.3) !important;
position: fixed !important;
top: 10px !important;
left: 250px !important;
z-index: 9999 !important;
width: 40px !important;
height: 40px !important;
min-width: 40px !important;
min-height: 40px !important;
padding: 8px !important;
opacity: 1 !important;
visibility: visible !important;
}
button[kind="icon"][data-testid="collapsedControl"]:hover,
[data-testid="collapsedControl"]:hover,
.stSidebarToggle:hover {
background-color: #DC2626 !important;
transform: scale(1.05);
}
button[kind="icon"][data-testid="collapsedControl"] svg,
[data-testid="collapsedControl"] svg,
.stSidebarToggle svg {
fill: #FFFFFF !important;
stroke: #FFFFFF !important;
}
/* Radio */
.stRadio > div { background: #F1F5F9 !important; border-radius: 8px !important; padding: 0.5rem !important; }
.stRadio label span { color: #475569 !important; }
/* Alerts */
.stAlert { background: #F1F5F9 !important; border: 1px solid #E2E8F0 !important; border-radius: 10px !important; }
.stAlert [data-testid="stAlertContent"] { color: #0F172A !important; }
/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #F8FAFC; }
::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }
/* Plotly */
.js-plotly-plot .plotly { border-radius: 10px; }
"""
def apply_theme():
"""Inject theme CSS into Streamlit."""
js_code = """
<script>
(function() {
function adjustSidebarTogglePosition() {
// Find the sidebar toggle button
const toggleButtons = document.querySelectorAll('button[kind="icon"][data-testid="collapsedControl"]');
const sidebar = document.querySelector('section[data-testid="stSidebar"]');
if (toggleButtons.length > 0 && sidebar) {
const toggle = toggleButtons[0];
// Get sidebar width to determine if it's expanded or collapsed
const computedStyle = window.getComputedStyle(sidebar);
const sidebarWidth = parseFloat(computedStyle.width);
// If sidebar width is small (~4.5rem or ~72px), it's collapsed
// If wider (~260px+), it's expanded
if (sidebarWidth > 200) {
// Sidebar is expanded - position toggle at 250px
toggle.style.left = '250px';
} else {
// Sidebar is collapsed - position toggle at 10px
toggle.style.left = '10px';
}
}
}
// Run immediately
adjustSidebarTogglePosition();
// Run when the page loads
window.addEventListener('load', adjustSidebarTogglePosition);
// Run periodically to catch sidebar state changes
setInterval(adjustSidebarTogglePosition, 500);
// Watch for DOM mutations that might affect sidebar
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'attributes' &&
(mutation.attributeName === 'style' || mutation.target.matches('[data-testid="stSidebar"]'))) {
setTimeout(adjustSidebarTogglePosition, 100);
}
});
});
observer.observe(document.body, {
attributes: true,
subtree: true,
attributeFilter: ['style', 'class']
});
})();
</script>
"""
st.markdown(f"<style>{CSS}</style>", unsafe_allow_html=True)
st.components.v1.html(js_code, height=0)
def apply_page_config():
"""Set Streamlit page config."""
st.set_page_config(
page_title="F1 Predictor 2026",
page_icon="ποΈ",
layout="wide",
initial_sidebar_state="expanded",
) |