Spaces:
Build error
Build error
leo1erstark
commited on
Commit
•
9c5378f
1
Parent(s):
75db584
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import seaborn as sns
|
6 |
+
import pickle
|
7 |
+
import base64
|
8 |
+
from catboost import CatBoostRegressor
|
9 |
+
|
10 |
+
@st.cache_data
|
11 |
+
def load_data(dataset):
|
12 |
+
df = pd.read_csv(dataset)
|
13 |
+
return df
|
14 |
+
|
15 |
+
def filedownload(df):
|
16 |
+
csv = df.to_csv(index=False)
|
17 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
18 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="concrete.csv">Download CSV File</a>'
|
19 |
+
return href
|
20 |
+
|
21 |
+
st.sidebar.image("ciment2.jpg", width=300)
|
22 |
+
|
23 |
+
def main():
|
24 |
+
st.markdown("<h1 style='text-align:center;color: brown;'>Streamlit Concrete Data App 👷♂️</h1>", unsafe_allow_html=True)
|
25 |
+
st.markdown("<h2 style='text-align:center;color: black;'>Concrete Data Analysis</h2>", unsafe_allow_html=True)
|
26 |
+
menu = ["🏛️Home", "🏗️Analysis", "🦺Data Visualization", "🚚Machine Learning"]
|
27 |
+
choice = st.sidebar.selectbox("Select Menu ", menu)
|
28 |
+
data = load_data("concrete.csv")
|
29 |
+
|
30 |
+
if choice == menu[0]:
|
31 |
+
left, middle, right = st.columns((2, 3, 2))
|
32 |
+
with middle:
|
33 |
+
st.image("ciment1.jpg", width=300)
|
34 |
+
st.write("This is an app that will analyze Concrete Datas with some python tools that can optimize decisions")
|
35 |
+
st.subheader("Concrete Dataset Informations")
|
36 |
+
st.write("The Concrete.csv dataset contains information about the composition and properties of different concrete mixtures. It includes variables such as cement, slag, fly ash, water, superplasticizer, coarse aggregate, fine aggregate, and the compressive strength of the concrete. This data can be used for various analyses and machine learning tasks related to concrete properties and optimization.")
|
37 |
+
|
38 |
+
elif choice == menu[1]:
|
39 |
+
st.subheader("Concrete")
|
40 |
+
st.write(data.head())
|
41 |
+
if st.checkbox("Summary"):
|
42 |
+
st.write(data.describe())
|
43 |
+
elif st.checkbox("Correlation"):
|
44 |
+
fig = plt.figure(figsize=(15, 15))
|
45 |
+
sns.heatmap(data.corr(), annot=True)
|
46 |
+
st.pyplot(fig)
|
47 |
+
|
48 |
+
elif choice == menu[2]:
|
49 |
+
if st.checkbox("CountPlot"):
|
50 |
+
fig = plt.figure(figsize=(15, 15))
|
51 |
+
sns.countplot(x="water", data=data)
|
52 |
+
st.pyplot(fig)
|
53 |
+
|
54 |
+
if st.checkbox("ScatterPlot"):
|
55 |
+
fig = plt.figure(figsize=(5, 5))
|
56 |
+
sns.scatterplot(x="coarseagg", y="water", data=data, hue="cement")
|
57 |
+
st.pyplot(fig)
|
58 |
+
|
59 |
+
if st.checkbox("Outliers"):
|
60 |
+
num_cols = len(data.columns)
|
61 |
+
num_rows = (num_cols - 1) // 4 + 1
|
62 |
+
|
63 |
+
fig, axes = plt.subplots(num_rows, 4, figsize=(16, num_rows * 4))
|
64 |
+
columns = data.columns
|
65 |
+
|
66 |
+
for i, column in enumerate(columns):
|
67 |
+
ax = axes[i // 4, i % 4]
|
68 |
+
sns.boxplot(y=data[column], ax=ax)
|
69 |
+
ax.set_title(column)
|
70 |
+
|
71 |
+
for j in range(num_cols, num_rows * 4):
|
72 |
+
fig.delaxes(axes.flatten()[j])
|
73 |
+
|
74 |
+
st.pyplot(fig)
|
75 |
+
|
76 |
+
elif choice == menu[3]:
|
77 |
+
tab1, tab2, tab3 = st.tabs([":clipboard: Data ", ":bar_chart: Visualisation", "⛏️ Prediction"])
|
78 |
+
uploaded_file = st.sidebar.file_uploader("Upload your csv file here", type=["csv"])
|
79 |
+
if uploaded_file:
|
80 |
+
dfs = load_data(uploaded_file)
|
81 |
+
with tab1:
|
82 |
+
st.subheader("Loaded dataset")
|
83 |
+
st.write(dfs)
|
84 |
+
|
85 |
+
with tab2:
|
86 |
+
st.subheader("Histogram Of coarseagg")
|
87 |
+
fig = plt.figure(figsize=(8, 8))
|
88 |
+
sns.histplot(x="coarseagg", data=data)
|
89 |
+
st.pyplot(fig)
|
90 |
+
|
91 |
+
with tab3:
|
92 |
+
pickled_model = pickle.load(open("final2concrete.pkl", "rb"))
|
93 |
+
pred = pickled_model.predict(dfs)
|
94 |
+
pp = pd.DataFrame(pred, columns=["predictions"])
|
95 |
+
ndf = pd.concat([dfs, pp], axis=1)
|
96 |
+
ndf["predictions"].replace(0, inplace=True)
|
97 |
+
ndf["predictions"].replace(1, inplace=True)
|
98 |
+
st.write(ndf)
|
99 |
+
button = st.button("Download")
|
100 |
+
if button:
|
101 |
+
st.markdown(filedownload(ndf), unsafe_allow_html=True)
|
102 |
+
st.subheader("Pairplot")
|
103 |
+
sns.pairplot(data)
|
104 |
+
st.pyplot(fig)
|
105 |
+
|
106 |
+
main()
|