File size: 5,090 Bytes
d1f8a0a b4e8d37 |
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 |
import streamlit as st
import pandas as pd
import numpy as np
import joblib
# Custom CSS for styling
st.markdown("""
<style>
/* General styling */
body {
background-color: #f0f2f6;
font-family: 'Arial', sans-serif;
}
.stApp {
max-width: 1200px;
margin: 0 auto;
}
/* Title */
.title {
color: #2c3e50;
font-size: 2.5em;
text-align: center;
margin-bottom: 0.5em;
}
/* Subheader */
.subheader {
color: #3498db;
font-size: 1.2em;
text-align: center;
margin-bottom: 2em;
}
/* Input containers */
.input-container {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
/* Button styling */
.stButton>button {
background-color: #1a10e3;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-weight: bold;
transition: all 0.3s ease;
}
.stButton>button:hover {
background-color: #c0392b;
transform: scale(1.05);
}
/* Success message */
.stSuccess {
background-color: #2ecc71 !important;
color: white !important;
padding: 15px;
border-radius: 5px;
text-align: center;
font-size: 1.2em;
}
/* Dataframe styling */
.dataframe {
border: 2px solid #3498db;
border-radius: 5px;
padding: 10px;
}
/* Footer */
.footer {
text-align: center;
color: #7f8c8d;
margin-top: 30px;
font-size: 0.9em;
}
.footer b {
color: #e74c3c;
}
/* Sidebar */
.sidebar .sidebar-content {
background-color: #34495e;
color: white;
padding: 20px;
}
</style>
""", unsafe_allow_html=True)
# Load the saved model and scaler
model = joblib.load('srn_rvp_model_version_2.pkl')
scaler = joblib.load('srn_rvp_scaler_version_2.pkl')
# Define feature names and default values
features = ['C_101_Top Temp', 'Stabiliser_feed', 'Kero_DOT ', 'Stab_Tray_3_temp ',
'Kero _reboiler_inlet_temp', 'Stab_top_pr', 'LGO_DOT', 'mp_stm_HGO_strp']
default_values = [130.0, 180.0, 200.0, 130.0, 250.0, 8.0, 270.0, 140.0]
# Sidebar for additional info
with st.sidebar:
st.markdown("<h2 style='color: #ecf0f1;'>About</h2>", unsafe_allow_html=True)
st.write("""
This app predicts the **SRN RVP (Reid Vapor Pressure)** lab value for a Crude Distillation Unit (CDU) using a pre-trained machine learning model.
**Features Used:**
- Temperature measurements
- Pressure readings
- Flow rates
""")
st.image("distillation.jpg", caption="Refinery Process Predictive Modeling")
# Main app content
st.markdown("<h1 class='title'>🔬 CDU SRN 'RVP' Prediction Tool</h1>", unsafe_allow_html=True)
st.markdown("<p class='subheader'>Enter process parameters to predict the lab RVP value</p>", unsafe_allow_html=True)
# Input form in columns for better layout
st.markdown("<div class='input-container'>", unsafe_allow_html=True)
st.write("### Input Process Parameters")
col1, col2 = st.columns(2)
input_data = {}
for i, (feature, default) in enumerate(zip(features, default_values)):
with col1 if i % 2 == 0 else col2:
input_data[feature] = st.number_input(
feature,
min_value=0.0,
max_value=1000.0,
value=float(default),
step=1.0,
format="%.1f",
key=feature
)
st.markdown("</div>", unsafe_allow_html=True)
# Convert inputs to DataFrame
input_df = pd.DataFrame([input_data], columns=features)
# Predict button
if st.button("🔍 Predict Lab Value"):
# Scale the input data
input_scaled = scaler.transform(input_df)
# Make prediction
prediction = model.predict(input_scaled)[0]
# Display result with animation
st.markdown(f"""
<div class='stSuccess'>
Predicted RVP Lab Value: <b>{prediction:.4f} psi</b>
</div>
""", unsafe_allow_html=True)
# Display input values with corrected precision formatting
st.write("### Your Input Values")
# Use format() to set precision to 2 decimal places
styled_df = input_df.style.highlight_max(axis=0).format("{:.2f}")
st.dataframe(styled_df, use_container_width=True)
# Instructions expander
with st.expander("ℹ️ How to Use", expanded=False):
st.markdown("""
1. **Enter Values**: Adjust the input fields for each parameter.
2. **Predict**: Click the "Predict Lab Value" button.
3. **Review**: Check the predicted RVP and input values below.
*Note*: This ML model is trained on refinery-specific data and uses scaled features for predictions.
""")
# Footer
st.markdown("""
<div class='footer'>
Developed by <b>SKB</b> | © 2025 All Rights Reserved
</div>
""", unsafe_allow_html=True) |