Lydienne commited on
Commit
db568c9
1 Parent(s): 732ae55

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -0
app.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import pickle
5
+
6
+ # Charger le jeu de données initial
7
+ data = pd.read_csv('concrete.csv')
8
+
9
+ # Créer un dictionnaire de correspondance entre les noms de colonnes et les noms de variables
10
+ column_name_mapping = {
11
+ 'cement': 'cement',
12
+ 'slag': 'slag',
13
+ 'ash': 'ash',
14
+ 'water': 'water',
15
+ 'superplastic': 'superplastic',
16
+ 'fineagg': 'fineagg',
17
+ 'age': 'age'
18
+ }
19
+
20
+ # Charger le modèle de régression enregistré avec pickle
21
+ with open('best_model.pkl', 'rb') as f:
22
+ best_model = pickle.load(f)
23
+
24
+ # Configuration de la mise en page
25
+ st.set_page_config(layout='wide', initial_sidebar_state='expanded')
26
+
27
+ # Définir le style CSS
28
+ with open('style.css') as f:
29
+ st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
30
+
31
+ # Barre latérale avec les paramètres de visualisation et de prédiction
32
+ with st.sidebar:
33
+ st.title('Concrete Data APP')
34
+ st.image('concrete.jpg')
35
+
36
+ st.subheader('Heat map parameter')
37
+ cement_value = st.selectbox('Age', data['age'].unique())
38
+
39
+ st.subheader('Donut chart parameter')
40
+ slag_value = st.selectbox('Select data', data['slag'].unique())
41
+
42
+ st.subheader('Line chart parameters')
43
+ plot_data = st.multiselect('Select data', ['cement', 'slag', 'ash'], ['cement', 'slag', 'ash'])
44
+ plot_height = st.slider('Specify plot height', 200, 500, 250)
45
+
46
+ st.subheader('Prediction')
47
+ do_prediction = st.checkbox('Perform prediction')
48
+
49
+ st.subheader('Upload Dataset')
50
+ uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
51
+ if uploaded_file is not None:
52
+ try:
53
+ data = pd.read_csv(uploaded_file)
54
+ except pd.errors.EmptyDataError:
55
+ st.error("Error: The uploaded CSV file is empty or could not be read.")
56
+ except Exception as e:
57
+ st.error(f"An error occurred: {str(e)}")
58
+
59
+ # Row A
60
+ st.markdown('### Metrics')
61
+ col1, col2, col3 = st.columns(3)
62
+
63
+ # Nombre d'échantillons
64
+ num_samples = 905
65
+ col1.metric("Number of Samples", 905)
66
+
67
+ # strength moyen
68
+ average_strength = data['superplastic'].mean()
69
+ col2.metric("Average superplastic", f"{average_strength:.2f}")
70
+
71
+ # cement moyen
72
+ average_cement = data['cement'].mean()
73
+ col3.metric("Average Cement", f"{average_cement:.2f}")
74
+
75
+ # Row B
76
+ st.markdown('### Donut chart')
77
+ top_10_ash = data['ash'].value_counts().head(10).index.tolist()
78
+ top_10_data = data[data['ash'].isin(top_10_ash)]
79
+ donut_fig = px.pie(top_10_data, names='ash', hole=0.5)
80
+ st.plotly_chart(donut_fig, use_container_width=True)
81
+
82
+ # Row C
83
+ st.markdown('### Line chart')
84
+ st.line_chart(data[plot_data], height=plot_height)
85
+
86
+ # Prediction Section
87
+ if do_prediction:
88
+ st.markdown('### Predicted strength')
89
+ cement = st.number_input('Cement', min_value=100.0, max_value=600.0, value=300.0, step=1.0, key='cement')
90
+ slag = st.number_input('Slag', min_value=0.0, max_value=300.0, value=100.0, step=1.0, key='slag')
91
+ ash = st.number_input('ash', min_value=0.0, max_value=200.0, value=50.0, step=1.0, key='ash')
92
+ water = st.number_input('Water', min_value=100.0, max_value=300.0, value=200.0, step=1.0, key='water')
93
+ superplastic = st.number_input('Superplastic', min_value=0.0, max_value=20.0, value=5.0, step=0.1, key='superplastic')
94
+ coarseagg = st.number_input('Coarse Aggregate', min_value=600.0, max_value=1200.0, value=1000.0, step=1.0, key='coarseagg')
95
+ fineagg = st.number_input('Fine Aggregate', min_value=500.0, max_value=1000.0, value=600.0, step=1.0, key='fineagg')
96
+ age = st.number_input('Age', min_value=1, max_value=365, value=28, step=1, key='age')
97
+
98
+ input_data = pd.DataFrame({
99
+ 'cement': [cement],
100
+ 'slag': [slag],
101
+ 'ash': [ash],
102
+ 'water': [water],
103
+ 'superplastic': [superplastic],
104
+ 'coarseagg': [coarseagg],
105
+ 'fineagg': [fineagg],
106
+ 'age': [age]
107
+ })
108
+
109
+ if st.button('Predict'):
110
+ predicted_strength = best_model.predict(input_data)
111
+ st.write(f'Predicted strength: {predicted_strength[0]:.2f}')