Meera2602 commited on
Commit
64e0d13
โ€ข
1 Parent(s): 407d829

app.py updated

Browse files
Files changed (1) hide show
  1. app.py +102 -151
app.py CHANGED
@@ -2,180 +2,131 @@ import streamlit as st
2
  from streamlit_extras import add_vertical_space
3
  import streamlit.components.v1 as components
4
  from annotated_text import annotated_text
5
-
6
-
7
- st.set_page_config(layout='wide')
8
-
9
  import pandas as pd
10
-
11
  import json
12
  import plotly.express as px
13
  import plotly.graph_objs as go
14
-
15
  from src.Predictive_Maintenance.pipelines.prediction_pipeline import prediction
16
 
17
- with st.sidebar:
18
- st.title("Predictive Maintenance Project")
19
-
20
- choice = st.radio("Choose from the below options:", ["Main","EDA","Monitoring Reports","Performance Measures","Prediction"])
21
-
22
-
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
 
 
25
 
26
  if choice == "Main":
27
  with open("frontend/main/main_page.md", "r") as file:
28
  readme_contents = file.read()
29
  st.markdown(readme_contents)
30
-
31
-
32
-
33
- if choice == "EDA":
34
- st.title('Exploratory Data Analysis')
35
-
36
- st.header('Question 1')
37
- st.write("What is the frequency distribution of the target label 'machine failure' in the dataset? How many instances indicate a failure compared to those that do not??")
38
- st.image("reports/q1.png")
39
- st.write("**The success rate of the machine is 96.52% and the highest type of failure is HDF(Heat Dissipation Failure) with 1.15% failure rate**")
40
-
41
-
42
- st.header('Question 2')
43
- st.write("How is the 'productID' variable distributed across the dataset? Specifically, how many instances correspond to low, medium, and high-quality variants?")
44
- st.image("reports/q2.png")
45
- st.write("**Low quality varient makes up majority of the dataset with 60% of the data, followed by medium quality varient with 30% and high quality varient with 10%**")
46
-
47
-
48
- st.header('Question 3')
49
- st.write("What are the minimum, maximum, and typical values for 'air temperature', 'process temperature', 'rotational speed', 'torque', and 'tool wear'?")
50
- st.write("Are there any significant outliers in these variables?")
51
- st.image("reports/q3.png")
52
- st.write("**Rotational speed may or may not be actual outliers, therefore we'll keep them in the dataset for now.**")
53
-
54
-
55
- st.header('Question 4')
56
- st.write("Is there any correlation between the continuous variables and the 'machine failure' label? For example, does the tool wear increase the likelihood of machine failure?")
57
- st.image("reports/q4.png")
58
- st.write("**Null Hypothesis: There is no significant relationship between the different colums and Machine Failure**")
59
- st.write("**Alternate Hypothesis: There is a significant relationship between the tool wear and the machine failure label**")
60
- st.image("reports/h0.png")
61
-
62
-
63
- st.header('Question 5')
64
- st.write("Is there any correlation between the categorical variable 'productID' and the continuous variable? For example, is the 'rotational speed' higher for high-quality products than for low-quality products? ")
65
- st.image("reports/q5.png")
66
- st.write("**Process Temperature seems to have an effect on high quality varient machines. Therefore we can say that Process Temperature is correlated with machine type.**")
67
-
68
- st.header('Question 6')
69
- st.write("Are there any significant interactions or non-linear relationships between the variables that could be important for predictive maintenance? For example, does torque increase non-linearly with rotational speed?")
70
- st.image("reports/q5.png")
71
- st.write("**Process Temperature seems to have an effect on high quality varient machines. Therefore we can say that Process Temperature is correlated with machine type.**")
72
-
73
- st.header('Question 7')
74
- st.write("Are there any discernible patterns or anomalies in the timing of machine failures?How do machine failure rates change over time? ")
75
- st.image("reports/q5.png")
76
- st.write("**Process Temperature seems to have an effect on high quality varient machines. Therefore we can say that Process Temperature is correlated with machine type.**")
77
-
78
- st.header('Question 8')
79
- st.write("Do the distributions of continuous variables differ significantly across various product types?")
80
- st.image("reports/q5.png")
81
- # st.write("**Process Temperature seems to have an effect on high quality varient machines. Therefore we can say that Process Temperature is correlated with machine type.**")
82
-
83
- st.header('Question 9')
84
- st.write("How does machine failure frequency vary with different operating conditions, such as changes in air temperature and rotational speed?")
85
- st.image("reports/q5.png")
86
- st.write("**Process Temperature seems to have an effect on high quality varient machines. Therefore we can say that Process Temperature is correlated with machine type.**")
87
-
88
-
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
 
 
 
91
 
 
92
 
93
- if choice == "Performance Measures":
94
-
95
- st.title("Model 1")
96
- annotated_text(("Best Model 1", "Random Forest Classifier"))
97
- st.image("reports/model1n.png")
98
-
99
-
100
-
101
- st.title("Model 2")
102
- annotated_text(("Best Model 2", "Random Forest Classifier-registered"))
103
- st.image("reports/model2n.png")
104
-
105
-
106
-
107
-
108
-
109
- if choice == "Monitoring Reports":
110
-
111
- options = st.selectbox('Choose the reports: ',('Data Report', 'Model 1 report', 'Model 2 report'))
112
-
113
- if options=='Data Report':
114
- with open("reports/data_drift.html", "r",encoding="utf-8") as f:
115
- html_report = f.read()
116
-
117
- components.html(html_report, scrolling=True, height=700)
118
-
119
 
120
- if options=='Model 1 report':
121
- with open("reports/classification_performance_report.html", "r",encoding="utf-8") as f:
122
- html_report = f.read()
123
 
124
- components.html(html_report, height=750, scrolling=True)
125
-
126
- if options=='Model 2 report':
127
- with open("reports/classification_performance_report2.html", "r",encoding="utf-8") as f:
128
- html_report = f.read()
 
129
 
130
- components.html(html_report, height=750, scrolling=True)
 
131
 
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
- if choice == "Prediction":
140
-
141
- st.title('Predictive Maintenance')
142
- st.write("**Please enter the following parameters**")
143
-
144
- type = st.selectbox(
145
- 'Type',('Low', 'Medium', 'High'))
146
-
147
- st.write('You selected:', type)
148
-
149
- rpm = st.number_input('RPM', value=1500.0)
150
- st.write('The current rpm is ', rpm)
151
-
152
- torque = st.number_input('Torque', value=75)
153
- st.write('The current rpm is ', torque)
154
-
155
- tool_wear = st.number_input('Tool Wear', value=25.00)
156
- st.write('The current rpm is ', tool_wear)
157
-
158
- air_temp = st.number_input('Air Temperature', value=35.4)
159
- st.write('The current rpm is ', air_temp)
160
-
161
- process_temp = st.number_input('Process Temperature', value=46.65)
162
- st.write('The current rpm is ', process_temp)
163
 
164
  if st.button("Predict"):
165
-
166
  result1, result2 = prediction(type, rpm, torque, tool_wear, air_temp, process_temp)
167
-
168
  st.write("Machine Failure?: ", result1)
169
  st.write("Type of Failure: ", result2)
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
- #type, rpm, torque, tool_wear, air_temp, process_temp
 
2
  from streamlit_extras import add_vertical_space
3
  import streamlit.components.v1 as components
4
  from annotated_text import annotated_text
 
 
 
 
5
  import pandas as pd
 
6
  import json
7
  import plotly.express as px
8
  import plotly.graph_objs as go
 
9
  from src.Predictive_Maintenance.pipelines.prediction_pipeline import prediction
10
 
11
+ st.set_page_config(layout='wide')
 
 
 
 
 
12
 
13
+ # Custom CSS to further beautify the app
14
+ st.markdown("""
15
+ <style>
16
+ /* Change the background color */
17
+ .stApp {
18
+ background-color: #F0F0F0;
19
+ }
20
+ /* Customize sidebar */
21
+ .css-1lcbmhc {
22
+ background-color: #E8E8E8 !important;
23
+ }
24
+ /* Style headings */
25
+ h1 {
26
+ color: #1E90FF;
27
+ }
28
+ h2 {
29
+ color: #1E90FF;
30
+ }
31
+ h3 {
32
+ color: #1E90FF;
33
+ }
34
+ /* Style text */
35
+ .css-1v3fvcr p {
36
+ color: #000000;
37
+ }
38
+ </style>
39
+ """, unsafe_allow_html=True)
40
 
41
+ with st.sidebar:
42
+ st.title("๐Ÿ”ง Predictive Maintenance Project")
43
+ choice = st.radio("Choose from the below options:", ["Main", "EDA", "Monitoring Reports", "Performance Measures", "Prediction"])
44
 
45
  if choice == "Main":
46
  with open("frontend/main/main_page.md", "r") as file:
47
  readme_contents = file.read()
48
  st.markdown(readme_contents)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ elif choice == "EDA":
51
+ st.title('๐Ÿ” Exploratory Data Analysis')
52
+
53
+ questions = [
54
+ ("What are the minimum, maximum, and typical values for 'air temperature', 'process temperature', 'rotational speed', 'torque', and 'tool wear'?", "reports/q3.png", "Rotational speed may or may not be actual outliers, therefore we keep them in the dataset for now."),
55
+ ("How is the 'productID' variable distributed across the dataset? Specifically, how many instances correspond to low, medium, and high-quality variants?", "reports/q2.png", "Low quality variant makes up majority of the dataset with 60% of the data, followed by medium quality variant with 30% and high quality variant with 10%"),
56
+ ("What is the frequency distribution of the target label 'machine failure' in the dataset? How many instances indicate a failure compared to those that do not?", "reports/q1.png", "The success rate of the machine is 96.52% and the highest type of failure is HDF (Heat Dissipation Failure) with 1.15% failure rate."),
57
+ ("Is the 'rotational speed' higher for high-quality products than for low-quality products? Is there any correlation of 'productIDs' with other continuous variable?", "reports/q5.png", "Process Temperature seems to have an effect on high quality variant machines. Therefore we can say that Process Temperature is correlated with machine type."),
58
+ ("Is there any correlation between the continuous variables and the 'machine failure' label? For example, does the tool wear increase the likelihood of machine failure?", "reports/q4.png", "Null Hypothesis: There is no significant relationship between the different columns and Machine Failure\nAlternate Hypothesis: There is a significant relationship between the tool wear and the machine failure label", "reports/h0.png"),
59
+ ("Are there any significant interactions or non-linear relationships between the variables that could be important for predictive maintenance? For example, does torque increase non-linearly with rotational speed?", "reports/q6.png", "Among all possible combinations of continuous variables, Rotational Speed vs Torque have a negative correlation and process temperature vs air temperature have a positive correlation."),
60
+ ("Are there any discernible patterns or anomalies in the timing of machine failures? How do machine failure rates change over time?", None, "At present the data does not show recorded time of the failure neither it shows the time of sensor data capture. Hence it is difficult to comment on failure rates over time."),
61
+ ("Are there any notable differences in the distribution of continuous variables between different product types?", "reports/q8.png", "Process Temperature seems to have an effect on high quality variant machines. Therefore we can say that Process Temperature is correlated with machine type."),
62
+ ("How does the occurrence of machine failure vary with different operating conditions, such as air temperature and rotational speed?", "reports/q92.png", "Process Temperature seems to have an effect on high quality variant machines. Therefore we can say that Process Temperature is correlated with machine type.")
63
+ ]
64
+
65
+ for idx, (question, img, explanation, *extra_img) in enumerate(questions):
66
+ st.header(f'Question {idx + 1}')
67
+ st.write(question)
68
+ if img:
69
+ st.image(img)
70
+ st.write(f"**{explanation}**")
71
+ if extra_img:
72
+ st.image(extra_img[0])
73
+
74
+ elif choice == "Performance Measures":
75
+ st.title("๐Ÿ“ˆ Performance Measures")
76
+
77
+ models = [
78
+ ("Model 1", "Random Forest Classifier", "reports/model1n.png"),
79
+ ("Model 2", "Random Forest Classifier-registered", "reports/model2n.png")
80
+ ]
81
+
82
+ for model_title, model_description, img in models:
83
+ st.title(model_title)
84
+ annotated_text((f"Best {model_title}", model_description))
85
+ st.image(img)
86
+
87
+ elif choice == "Monitoring Reports":
88
+ st.title("๐Ÿ“Š Monitoring Reports")
89
+
90
+ options = st.selectbox('Choose the reports:', ('Data Report', 'Model 1 report', 'Model 2 report'))
91
+
92
+ report_files = {
93
+ 'Data Report': "reports/data_drift.html",
94
+ 'Model 1 report': "reports/classification_performance_report.html",
95
+ 'Model 2 report': "reports/classification_performance_report2.html"
96
+ }
97
+
98
+ if options in report_files:
99
+ with open(report_files[options], "r", encoding="utf-8") as f:
100
+ html_report = f.read()
101
+ components.html(html_report, scrolling=True, height=700)
102
 
103
+ elif choice == "Prediction":
104
+ st.title('๐Ÿ”ฎ Predictive Maintenance')
105
+ st.write("**Please enter the following parameters**")
106
 
107
+ col1, col2 = st.columns(2)
108
 
109
+ with col1:
110
+ type = st.selectbox('Type', ('Low', 'Medium', 'High'))
111
+ st.write('You selected:', type)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
+ rpm = st.number_input('RPM', value=1500.0)
114
+ st.write('The current rpm is ', rpm)
 
115
 
116
+ torque = st.number_input('Torque', value=75)
117
+ st.write('The current torque is ', torque)
118
+
119
+ with col2:
120
+ tool_wear = st.number_input('Tool Wear', value=25.00)
121
+ st.write('The current tool wear is ', tool_wear)
122
 
123
+ air_temp = st.number_input('Air Temperature', value=35.4)
124
+ st.write('The current air temperature is ', air_temp)
125
 
126
+ process_temp = st.number_input('Process Temperature', value=46.65)
127
+ st.write('The current process temperature is ', process_temp)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  if st.button("Predict"):
 
130
  result1, result2 = prediction(type, rpm, torque, tool_wear, air_temp, process_temp)
 
131
  st.write("Machine Failure?: ", result1)
132
  st.write("Type of Failure: ", result2)