import streamlit as st
import pandas as pd
import numpy as np
import joblib
# Custom CSS for styling
st.markdown("""
""", 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("
About
", 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("🔬 CDU SRN 'RVP' Prediction Tool
", unsafe_allow_html=True)
st.markdown("", unsafe_allow_html=True)
# Input form in columns for better layout
st.markdown("", 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("
", 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"""
Predicted RVP Lab Value: {prediction:.4f} psi
""", 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("""
""", unsafe_allow_html=True)