Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +65 -79
src/streamlit_app.py
CHANGED
|
@@ -26,8 +26,7 @@ from evolution_optimized import (
|
|
| 26 |
st.set_page_config(
|
| 27 |
page_title="Diesel Fuel Optimizer",
|
| 28 |
page_icon="⛽",
|
| 29 |
-
layout="wide"
|
| 30 |
-
initial_sidebar_state="expanded"
|
| 31 |
)
|
| 32 |
|
| 33 |
# Custom CSS
|
|
@@ -63,84 +62,91 @@ st.markdown("""
|
|
| 63 |
# Header
|
| 64 |
st.markdown('<p class="main-header">⛽ Diesel Fuel Optimizer</p>', unsafe_allow_html=True)
|
| 65 |
st.markdown("**Generate optimized diesel fuel candidates using evolutionary algorithms**")
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
with st.sidebar:
|
| 71 |
-
st.subheader("Target Properties")
|
| 72 |
-
target_cn = st.number_input(
|
| 73 |
-
"Target Cetane Number (CN)",
|
| 74 |
-
min_value=40.0,
|
| 75 |
-
max_value=100.0,
|
| 76 |
-
value=50.0,
|
| 77 |
-
step=1.0,
|
| 78 |
-
help="Desired cetane number for fuel candidates"
|
| 79 |
-
)
|
| 80 |
-
|
| 81 |
-
minimize_ysi = st.checkbox(
|
| 82 |
-
"Minimize Yield Sooting Index (YSI)",
|
| 83 |
-
value=True,
|
| 84 |
-
help="Optimize for lower soot emissions"
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
st.divider()
|
| 88 |
-
|
| 89 |
-
st.subheader("🔬 Advanced Settings")
|
| 90 |
-
|
| 91 |
-
with st.expander("Algorithm Parameters"):
|
| 92 |
generations = st.slider(
|
| 93 |
-
"
|
| 94 |
min_value=3,
|
| 95 |
max_value=20,
|
| 96 |
-
value=5
|
| 97 |
-
help="More generations = better results but slower"
|
| 98 |
)
|
| 99 |
-
|
| 100 |
population_size = st.slider(
|
| 101 |
"Population Size",
|
| 102 |
min_value=50,
|
| 103 |
max_value=300,
|
| 104 |
value=100,
|
| 105 |
-
step=50
|
| 106 |
-
help="Larger population = more diversity"
|
| 107 |
)
|
| 108 |
-
|
| 109 |
mutations_per_parent = st.slider(
|
| 110 |
"Mutations per Parent",
|
| 111 |
min_value=3,
|
| 112 |
max_value=10,
|
| 113 |
-
value=5
|
| 114 |
-
help="Number of variations to generate per molecule"
|
| 115 |
)
|
|
|
|
| 116 |
|
| 117 |
-
with st.expander("Property Constraints"):
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
| 139 |
|
| 140 |
-
st.divider()
|
| 141 |
|
| 142 |
# Run button
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# Main content
|
| 146 |
if 'results' not in st.session_state:
|
|
@@ -148,26 +154,6 @@ if 'results' not in st.session_state:
|
|
| 148 |
st.session_state.pareto = None
|
| 149 |
st.session_state.config = None
|
| 150 |
|
| 151 |
-
# Show initial dataset info
|
| 152 |
-
if st.session_state.results is None:
|
| 153 |
-
st.info("👈 Configure your optimization parameters in the sidebar and click **Run Optimization** to start!")
|
| 154 |
-
|
| 155 |
-
with st.expander("ℹ️ About This Tool"):
|
| 156 |
-
st.markdown("""
|
| 157 |
-
This tool uses **evolutionary algorithms** to discover optimal diesel fuel candidates:
|
| 158 |
-
|
| 159 |
-
1. **Define Target**: Set your desired cetane number and optimization goals
|
| 160 |
-
2. **Set Constraints**: Configure property filters (boiling point, density, LHV)
|
| 161 |
-
3. **Evolution**: The algorithm mutates and selects the best molecules over multiple generations
|
| 162 |
-
4. **Results**: Get ranked fuel candidates optimized for your specifications
|
| 163 |
-
|
| 164 |
-
**Key Metrics:**
|
| 165 |
-
- **Cetane Number (CN)**: Ignition quality (higher = better ignition)
|
| 166 |
-
- **Yield Sooting Index (YSI)**: Soot formation tendency (lower = cleaner)
|
| 167 |
-
- **Boiling Point (BP)**: Volatility indicator
|
| 168 |
-
- **Density**: Fuel density
|
| 169 |
-
- **Lower Heating Value (LHV)**: Energy content
|
| 170 |
-
""")
|
| 171 |
|
| 172 |
# Show dataset preview
|
| 173 |
st.subheader("📊 Initial Dataset")
|
|
|
|
| 26 |
st.set_page_config(
|
| 27 |
page_title="Diesel Fuel Optimizer",
|
| 28 |
page_icon="⛽",
|
| 29 |
+
layout="wide"
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
# Custom CSS
|
|
|
|
| 62 |
# Header
|
| 63 |
st.markdown('<p class="main-header">⛽ Diesel Fuel Optimizer</p>', unsafe_allow_html=True)
|
| 64 |
st.markdown("**Generate optimized diesel fuel candidates using evolutionary algorithms**")
|
| 65 |
+
st.header("⚙️ Optimization Configuration")
|
| 66 |
|
| 67 |
+
with st.container():
|
| 68 |
+
col_main, col_adv = st.columns([2, 1])
|
| 69 |
+
|
| 70 |
+
# === Main target controls ===
|
| 71 |
+
with col_main:
|
| 72 |
+
st.subheader("🎯 Target Properties")
|
| 73 |
+
|
| 74 |
+
target_cn = st.number_input(
|
| 75 |
+
"Target Cetane Number (CN)",
|
| 76 |
+
min_value=40.0,
|
| 77 |
+
max_value=100.0,
|
| 78 |
+
value=50.0,
|
| 79 |
+
step=1.0,
|
| 80 |
+
help="Desired cetane number for fuel candidates"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
minimize_ysi = st.checkbox(
|
| 84 |
+
"Minimize Yield Sooting Index (YSI)",
|
| 85 |
+
value=True,
|
| 86 |
+
help="Optimize for lower soot emissions"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# === Algorithm controls ===
|
| 90 |
+
with col_adv:
|
| 91 |
+
st.subheader("🧬 Algorithm Settings")
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
generations = st.slider(
|
| 94 |
+
"Generations",
|
| 95 |
min_value=3,
|
| 96 |
max_value=20,
|
| 97 |
+
value=5
|
|
|
|
| 98 |
)
|
| 99 |
+
|
| 100 |
population_size = st.slider(
|
| 101 |
"Population Size",
|
| 102 |
min_value=50,
|
| 103 |
max_value=300,
|
| 104 |
value=100,
|
| 105 |
+
step=50
|
|
|
|
| 106 |
)
|
| 107 |
+
|
| 108 |
mutations_per_parent = st.slider(
|
| 109 |
"Mutations per Parent",
|
| 110 |
min_value=3,
|
| 111 |
max_value=10,
|
| 112 |
+
value=5
|
|
|
|
| 113 |
)
|
| 114 |
+
|
| 115 |
|
| 116 |
+
with st.expander("🔬 Property Constraints", expanded=False):
|
| 117 |
+
|
| 118 |
+
use_bp_filter = st.checkbox("Filter by Boiling Point", value=True)
|
| 119 |
+
if use_bp_filter:
|
| 120 |
+
col1, col2 = st.columns(2)
|
| 121 |
+
with col1:
|
| 122 |
+
min_bp = st.number_input("Min BP (°C)", value=60.0)
|
| 123 |
+
with col2:
|
| 124 |
+
max_bp = st.number_input("Max BP (°C)", value=250.0)
|
| 125 |
+
else:
|
| 126 |
+
min_bp, max_bp = 60.0, 250.0
|
| 127 |
+
|
| 128 |
+
use_density_filter = st.checkbox("Filter by Density", value=True)
|
| 129 |
+
min_density = (
|
| 130 |
+
st.number_input("Min Density (kg/m³)", value=720.0)
|
| 131 |
+
if use_density_filter else 720.0
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
use_lhv_filter = st.checkbox("Filter by Lower Heating Value", value=True)
|
| 135 |
+
min_lhv = (
|
| 136 |
+
st.number_input("Min LHV (MJ/kg)", value=30.0)
|
| 137 |
+
if use_lhv_filter else 30.0
|
| 138 |
+
)
|
| 139 |
|
|
|
|
| 140 |
|
| 141 |
# Run button
|
| 142 |
+
st.divider()
|
| 143 |
+
|
| 144 |
+
run_optimization = st.button(
|
| 145 |
+
"🚀 Run Optimization",
|
| 146 |
+
type="primary",
|
| 147 |
+
use_container_width=True
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
|
| 151 |
# Main content
|
| 152 |
if 'results' not in st.session_state:
|
|
|
|
| 154 |
st.session_state.pareto = None
|
| 155 |
st.session_state.config = None
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
# Show dataset preview
|
| 159 |
st.subheader("📊 Initial Dataset")
|