Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files13 unmodified lines141516171819207 unmodified lines282930313233343536373839404142434425 unmodified lines7071727374757677787980818217 unmodified lines1001011021031041051067 unmodified lines1141151161171181191209 unmodified lines13013113213313413513699 unmodified lines23623723823924024124288 unmodified lines33133233333433533633756 unmodified lines3943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364373 unmodified lines44144244344444544644713 unmodified lines4614624634644654664674 unmodified lines4724734744754764774787 unmodified lines48648748848949049149213 unmodified lines)# ---------------------------# Global CSS (mac-neon + rev gauge)# ---------------------------st.markdown("""7 unmodified lines[data-testid="stHeader"] { background: transparent; }[data-testid="stToolbar"] { display: none; }.hero {border-radius: 24px;padding: 18px 22px;background: radial-gradient(circle at top left, rgba(96,165,250,0.35), transparent 55%),radial-gradient(circle at bottom right, rgba(236,72,153,0.35), transparent 55%),rgba(15,23,42,0.94);box-shadow: 0 25px 60px rgba(15,23,42,0.9);border: 1px solid rgba(148,163,184,0.35);position: relative;overflow: hidden;}.hero-title {font-size: 1.9rem;font-weight: 700;25 unmodified lines100% { background-position: 0% 50%; }}.glass {background: radial-gradient(circle at top left, rgba(148,163,184,0.24), transparent 55%),rgba(15,23,42,0.96);border-radius: 18px;padding: 18px 18px 14px 18px;border: 1px solid rgba(148,163,184,0.4);box-shadow: 0 20px 40px rgba(15,23,42,0.6);}.chip {17 unmodified linescolor: #6b7280;}/* Tabs */button[data-baseweb="tab"] {background: transparent !important;border-radius: 999px !important;7 unmodified linesbox-shadow: 0 0 0 1px rgba(59,130,246,0.7);}/* Rev limiter gauge */.rev-wrap {display:flex;justify-content:center;9 unmodified linesbackground: radial-gradient(circle at 50% 120%, #991b1b, transparent 60%),radial-gradient(circle at 0% 0%, rgba(59,130,246,0.4), transparent 60%),#020617;overflow:hidden;border:1px solid rgba(148,163,184,0.5);box-shadow: 0 12px 30px rgba(0,0,0,0.8);}99 unmodified linesmodel.fit(X_scaled, y)# ---------------------------# PRESET CALLBACKS (use session_state)# ---------------------------def preset_daily():s = st.session_state88 unmodified liness.traction_mode = "Track / Drag"# ---------------------------# HERO# ---------------------------st.markdown("""56 unmodified linestabs = st.tabs(["Core Specs", "Bolt-Ons", "Boost & Cooling", "ECU & Fuel"])# --- Core specs ---with tabs[0]:col1, col2 = st.columns(2)engine_disp_options = [0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.5,2.8,3.0,3.2,3.5,4.0,4.4,5.0,6.0,7.0,8.0]engine_disp = col1.selectbox("Engine Displacement (L)",engine_disp_options,index=engine_disp_options.index(2.0),key="engine_disp")engine_layout = col2.selectbox("Engine Layout",["I3","I4","I6","V6","V8","V10","V12"],index=2,key="engine_layout")layout_to_cyl = {"I3":3,"I4":4,"I6":6,"V6":6,"V8":8,"V10":10,"V12":12}cyl = layout_to_cyl[engine_layout]# FIX: Increased max_value to 3000 to prevent crash on high displacement/cylinder combinationsbase_hp = st.number_input("Base Horsepower (stock dyno)",min_value=60, max_value=3000,value=int(max(90, round(engine_disp * cyl * 20))),key="base_hp")col3, col4 = st.columns(2)weight_kg = col3.number_input("Vehicle Weight (kg)",min_value=700, max_value=4000, value=1500,key="weight_kg")weight_reduction = col4.slider("Weight Reduction (%)",0, 40, 0,key="weight_reduction")3 unmodified linesintake = col1.selectbox("Intake", ["Stock", "Cold Air", "Performance"], key="intake")headers = col2.selectbox("Headers", ["Stock", "Shorty", "Long Tube"], key="headers")exhaust = col3.selectbox("Exhaust", ["Stock", "Cat-back", "Straight Pipe"], key="exhaust")exhaust_dia = st.slider("Exhaust Diameter (mm)", 40, 120, 60, key="exhaust_dia")cam = st.selectbox("Cam Profile",13 unmodified lines["None", "Turbo", "Twin-Turbo", "Supercharger", "Twincharged"],key="induction")boost_psi = st.slider("Target Boost (psi)", 0, 40, 10, key="boost_psi")turbo_size = st.selectbox("Turbo Size",["N/A", "Small 45-55mm", "Medium 56-65mm", "Big 66-75mm", "XL 76mm+"],4 unmodified lines["None", "Air-to-Air", "Air-to-Water", "Front-mount High-Flow"],key="intercooler")meth = st.checkbox("Methanol Injection Kit", value=False, key="meth")# --- ECU & fuel ---with tabs[3]:7 unmodified lines["87", "91", "93", "E85 / Race Blend"],key="fuel")altitude = st.slider("Altitude (meters)", 0, 3500, 200, key="altitude")traction_mode = st.radio("Traction Mode Vibe",["Daily", "Spirited", "Track / Drag"],13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051525354557 unmodified lines6364656667686970717273747576777879808125 unmodified lines10710810911011111211311411511611711811912012117 unmodified lines1391401411421431441457 unmodified lines1531541551561571581599 unmodified lines16917017117217317417599 unmodified lines27527627727827928028188 unmodified lines37037137237337437537656 unmodified lines4334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784793 unmodified lines48348448548648748848913 unmodified lines5035045055065075085094 unmodified lines5145155165175185195207 unmodified lines52852953053153253353413 unmodified lines)# ---------------------------# SESSION STATE INITIALIZATION (Fixes Yellow Warning)# ---------------------------def init_session_state():# Only set these defaults if they don't exist yetdefaults = {"engine_disp": 2.0,"engine_layout": "I6","base_hp": 240,"weight_kg": 1500,"weight_reduction": 0,"intake": "Stock","headers": "Stock","exhaust": "Stock","exhaust_dia": 60,"cam": "Stock","intake_manifold": "Stock","induction": "None","boost_psi": 0,"turbo_size": "N/A","intercooler": "None","meth": False,"tune": "None","fuel": "93","altitude": 200,"traction_mode": "Spirited"}for key, value in defaults.items():if key not in st.session_state:st.session_state[key] = value# Run init immediatelyinit_session_state()# ---------------------------# Global CSS (Fixes "Cutting Out" / Rounds)# ---------------------------st.markdown("""7 unmodified lines[data-testid="stHeader"] { background: transparent; }[data-testid="stToolbar"] { display: none; }/* Fix: Removed overflow:hidden to stop cutting off shadows */.hero {border-radius: 24px;padding: 24px 28px;background: radial-gradient(circle at top left, rgba(96,165,250,0.35), transparent 55%),radial-gradient(circle at bottom right, rgba(236,72,153,0.35), transparent 55%),rgba(15,23,42,0.94);box-shadow: 0 20px 50px rgba(0,0,0,0.5);border: 1px solid rgba(148,163,184,0.35);position: relative;margin-bottom: 20px;}.hero-title {font-size: 1.9rem;font-weight: 700;25 unmodified lines100% { background-position: 0% 50%; }}/* Fix: Removed overflow:hidden and added margin for shadow breathing room */.glass {background: radial-gradient(circle at top left, rgba(148,163,184,0.24), transparent 55%),rgba(15,23,42,0.96);border-radius: 20px;padding: 20px;border: 1px solid rgba(148,163,184,0.4);box-shadow: 0 15px 35px rgba(0,0,0,0.6);margin: 5px;}.chip {17 unmodified linescolor: #6b7280;}/* Tabs styling */button[data-baseweb="tab"] {background: transparent !important;border-radius: 999px !important;7 unmodified linesbox-shadow: 0 0 0 1px rgba(59,130,246,0.7);}/* Rev limiter gauge - Only this keeps overflow hidden for the semi-circle */.rev-wrap {display:flex;justify-content:center;9 unmodified linesbackground: radial-gradient(circle at 50% 120%, #991b1b, transparent 60%),radial-gradient(circle at 0% 0%, rgba(59,130,246,0.4), transparent 60%),#020617;overflow:hidden;border:1px solid rgba(148,163,184,0.5);box-shadow: 0 12px 30px rgba(0,0,0,0.8);}99 unmodified linesmodel.fit(X_scaled, y)# ---------------------------# PRESET CALLBACKS# ---------------------------def preset_daily():s = st.session_state88 unmodified liness.traction_mode = "Track / Drag"# ---------------------------# HERO SECTION# ---------------------------st.markdown("""56 unmodified linestabs = st.tabs(["Core Specs", "Bolt-Ons", "Boost & Cooling", "ECU & Fuel"])# NOTE: I removed 'index=...' from these selectboxes.# They now just rely on the key being present in st.session_state (handled by init_session_state)# --- Core specs ---with tabs[0]:col1, col2 = st.columns(2)engine_disp_options = [0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.5,2.8,3.0,3.2,3.5,4.0,4.4,5.0,6.0,7.0,8.0]# We manually update value if it's missing (failsafe), though init handles it.if "engine_disp" not in st.session_state: st.session_state.engine_disp = 2.0engine_disp = col1.selectbox("Engine Displacement (L)",engine_disp_options,key="engine_disp")engine_layout = col2.selectbox("Engine Layout",["I3","I4","I6","V6","V8","V10","V12"],key="engine_layout")layout_to_cyl = {"I3":3,"I4":4,"I6":6,"V6":6,"V8":8,"V10":10,"V12":12}cyl = layout_to_cyl[engine_layout]base_hp = st.number_input("Base Horsepower (stock dyno)",min_value=60, max_value=3000,key="base_hp")col3, col4 = st.columns(2)weight_kg = col3.number_input("Vehicle Weight (kg)",min_value=700, max_value=4000,key="weight_kg")weight_reduction = col4.slider("Weight Reduction (%)",0, 40,key="weight_reduction")3 unmodified linesintake = col1.selectbox("Intake", ["Stock", "Cold Air", "Performance"], key="intake")headers = col2.selectbox("Headers", ["Stock", "Shorty", "Long Tube"], key="headers")exhaust = col3.selectbox("Exhaust", ["Stock", "Cat-back", "Straight Pipe"], key="exhaust")exhaust_dia = st.slider("Exhaust Diameter (mm)", 40, 120, key="exhaust_dia")cam = st.selectbox("Cam Profile",13 unmodified lines["None", "Turbo", "Twin-Turbo", "Supercharger", "Twincharged"],key="induction")boost_psi = st.slider("Target Boost (psi)", 0, 40, key="boost_psi")turbo_size = st.selectbox("Turbo Size",["N/A", "Small 45-55mm", "Medium 56-65mm", "Big 66-75mm", "XL 76mm+"],4 unmodified lines["None", "Air-to-Air", "Air-to-Water", "Front-mount High-Flow"],key="intercooler")meth = st.checkbox("Methanol Injection Kit", key="meth")# --- ECU & fuel ---with tabs[3]:7 unmodified lines["87", "91", "93", "E85 / Race Blend"],key="fuel")altitude = st.slider("Altitude (meters)", 0, 3500, key="altitude")traction_mode = st.radio("Traction Mode Vibe",["Daily", "Spirited", "Track / Drag"],
src/streamlit_app.py+64-22