|
import streamlit as st |
|
import pandas as pd |
|
import plotly.express as px |
|
import pickle |
|
|
|
|
|
data = pd.read_csv('concrete.csv') |
|
|
|
|
|
column_name_mapping = { |
|
'cement': 'cement', |
|
'slag': 'slag', |
|
'ash': 'ash', |
|
'water': 'water', |
|
'superplastic': 'superplastic', |
|
'fineagg': 'fineagg', |
|
'age': 'age' |
|
} |
|
|
|
|
|
with open('best_model.pkl', 'rb') as f: |
|
best_model = pickle.load(f) |
|
|
|
|
|
st.set_page_config(layout='wide', initial_sidebar_state='expanded') |
|
|
|
|
|
with open('style.css') as f: |
|
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True) |
|
|
|
|
|
with st.sidebar: |
|
st.title('Concrete Data APP') |
|
st.image('concrete.jpg') |
|
|
|
st.subheader('Heat map parameter') |
|
cement_value = st.selectbox('Age', data['age'].unique()) |
|
|
|
st.subheader('Donut chart parameter') |
|
slag_value = st.selectbox('Select data', data['slag'].unique()) |
|
|
|
st.subheader('Line chart parameters') |
|
plot_data = st.multiselect('Select data', ['cement', 'slag', 'ash'], ['cement', 'slag', 'ash']) |
|
plot_height = st.slider('Specify plot height', 200, 500, 250) |
|
|
|
st.subheader('Prediction') |
|
do_prediction = st.checkbox('Perform prediction') |
|
|
|
st.subheader('Upload Dataset') |
|
uploaded_file = st.file_uploader("Choose a CSV file", type="csv") |
|
if uploaded_file is not None: |
|
try: |
|
data = pd.read_csv(uploaded_file) |
|
except pd.errors.EmptyDataError: |
|
st.error("Error: The uploaded CSV file is empty or could not be read.") |
|
except Exception as e: |
|
st.error(f"An error occurred: {str(e)}") |
|
|
|
|
|
st.markdown('### Metrics') |
|
col1, col2, col3 = st.columns(3) |
|
|
|
|
|
num_samples = 905 |
|
col1.metric("Number of Samples", 905) |
|
|
|
|
|
average_strength = data['superplastic'].mean() |
|
col2.metric("Average superplastic", f"{average_strength:.2f}") |
|
|
|
|
|
average_cement = data['cement'].mean() |
|
col3.metric("Average Cement", f"{average_cement:.2f}") |
|
|
|
|
|
st.markdown('### Donut chart') |
|
top_10_ash = data['ash'].value_counts().head(10).index.tolist() |
|
top_10_data = data[data['ash'].isin(top_10_ash)] |
|
donut_fig = px.pie(top_10_data, names='ash', hole=0.5) |
|
st.plotly_chart(donut_fig, use_container_width=True) |
|
|
|
|
|
st.markdown('### Line chart') |
|
st.line_chart(data[plot_data], height=plot_height) |
|
|
|
|
|
if do_prediction: |
|
st.markdown('### Predicted strength') |
|
cement = st.number_input('Cement', min_value=100.0, max_value=600.0, value=300.0, step=1.0, key='cement') |
|
slag = st.number_input('Slag', min_value=0.0, max_value=300.0, value=100.0, step=1.0, key='slag') |
|
ash = st.number_input('ash', min_value=0.0, max_value=200.0, value=50.0, step=1.0, key='ash') |
|
water = st.number_input('Water', min_value=100.0, max_value=300.0, value=200.0, step=1.0, key='water') |
|
superplastic = st.number_input('Superplastic', min_value=0.0, max_value=20.0, value=5.0, step=0.1, key='superplastic') |
|
coarseagg = st.number_input('Coarse Aggregate', min_value=600.0, max_value=1200.0, value=1000.0, step=1.0, key='coarseagg') |
|
fineagg = st.number_input('Fine Aggregate', min_value=500.0, max_value=1000.0, value=600.0, step=1.0, key='fineagg') |
|
age = st.number_input('Age', min_value=1, max_value=365, value=28, step=1, key='age') |
|
|
|
input_data = pd.DataFrame({ |
|
'cement': [cement], |
|
'slag': [slag], |
|
'ash': [ash], |
|
'water': [water], |
|
'superplastic': [superplastic], |
|
'coarseagg': [coarseagg], |
|
'fineagg': [fineagg], |
|
'age': [age] |
|
}) |
|
|
|
if st.button('Predict'): |
|
predicted_strength = best_model.predict(input_data) |
|
st.write(f'Predicted strength: {predicted_strength[0]:.2f}') |
|
|