Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from sklearn.ensemble import RandomForestClassifier
|
5 |
+
from prophet import Prophet
|
6 |
+
|
7 |
+
# Load dataset
|
8 |
+
@st.cache_data
|
9 |
+
def load_data(filename):
|
10 |
+
return pd.read_csv(filename)
|
11 |
+
|
12 |
+
# Main application
|
13 |
+
st.sidebar.title("AI-Powered Industrial Management")
|
14 |
+
page = st.sidebar.radio("Choose a page", ["Predictive Maintenance for Wind Turbines", "Intelligent Energy Management Systems"])
|
15 |
+
|
16 |
+
# Predictive Maintenance for Wind Turbines
|
17 |
+
if page == "Predictive Maintenance for Wind Turbines":
|
18 |
+
st.header("Predictive Maintenance for Wind Turbines")
|
19 |
+
|
20 |
+
# Load and display dataset
|
21 |
+
data = load_data('wind_turbine_data.csv')
|
22 |
+
|
23 |
+
st.write("### Dataset Preview:")
|
24 |
+
st.write(data.head())
|
25 |
+
|
26 |
+
# Dataset Meta Information
|
27 |
+
st.write("### Dataset Meta Information:")
|
28 |
+
st.write("""
|
29 |
+
- **Timestamp:** The time at which the data was recorded.
|
30 |
+
- **Turbine_ID:** Unique identifier for each wind turbine.
|
31 |
+
- **Wind_Speed (m/s):** The speed of the wind at the time of measurement.
|
32 |
+
- **Ambient_Temperature (°C):** The outside temperature where the turbine is located.
|
33 |
+
- **Power_Output (MW):** The power generated by the turbine at the time of measurement.
|
34 |
+
- **Blade_Vibration (mm/s):** The vibration level of the turbine blades, a critical indicator of potential mechanical issues.
|
35 |
+
- **Gearbox_Temperature (°C):** Temperature inside the turbine's gearbox.
|
36 |
+
- **Oil_Level (%):** The level of lubrication oil in the turbine.
|
37 |
+
- **Maintenance_History (0/1):** Whether the turbine underwent maintenance in the last 30 days (1) or not (0).
|
38 |
+
- **Component_Failure (0/1):** Whether a component failure occurred (1) or not. This is the target variable.
|
39 |
+
""")
|
40 |
+
|
41 |
+
# Data Exploration
|
42 |
+
st.write("### Data Exploration")
|
43 |
+
|
44 |
+
# Select Graph Type
|
45 |
+
graph_type = st.selectbox("Select a graph to visualize:",
|
46 |
+
["Wind Speed Distribution",
|
47 |
+
"Ambient Temperature vs. Power Output",
|
48 |
+
"Blade Vibration vs. Gearbox Temperature",
|
49 |
+
"Oil Level Distribution"])
|
50 |
+
|
51 |
+
# Plotting based on selection
|
52 |
+
if graph_type == "Wind Speed Distribution":
|
53 |
+
st.write("#### Wind Speed Distribution")
|
54 |
+
plt.figure(figsize=(10, 6))
|
55 |
+
plt.hist(data['Wind_Speed'], bins=20, color='skyblue', edgecolor='black')
|
56 |
+
plt.xlabel('Wind Speed (m/s)')
|
57 |
+
plt.ylabel('Frequency')
|
58 |
+
plt.title('Distribution of Wind Speed')
|
59 |
+
st.pyplot(plt)
|
60 |
+
st.write("This graph shows the distribution of wind speeds recorded in the dataset. "
|
61 |
+
"It helps in understanding the common wind speeds at which the turbines operate, "
|
62 |
+
"which can be crucial for assessing turbine performance and predicting failures.")
|
63 |
+
|
64 |
+
elif graph_type == "Ambient Temperature vs. Power Output":
|
65 |
+
st.write("#### Ambient Temperature vs. Power Output")
|
66 |
+
plt.figure(figsize=(10, 6))
|
67 |
+
plt.scatter(data['Ambient_Temperature'], data['Power_Output'], color='green', alpha=0.6)
|
68 |
+
plt.xlabel('Ambient Temperature (°C)')
|
69 |
+
plt.ylabel('Power Output (MW)')
|
70 |
+
plt.title('Ambient Temperature vs. Power Output')
|
71 |
+
st.pyplot(plt)
|
72 |
+
st.write("This scatter plot illustrates the relationship between ambient temperature and power output. "
|
73 |
+
"It shows how temperature variations can affect the power generated by the wind turbines, "
|
74 |
+
"which is important for understanding operational efficiency under different weather conditions.")
|
75 |
+
|
76 |
+
elif graph_type == "Blade Vibration vs. Gearbox Temperature":
|
77 |
+
st.write("#### Blade Vibration vs. Gearbox Temperature")
|
78 |
+
plt.figure(figsize=(10, 6))
|
79 |
+
plt.scatter(data['Blade_Vibration'], data['Gearbox_Temperature'], color='orange', alpha=0.6)
|
80 |
+
plt.xlabel('Blade Vibration (mm/s)')
|
81 |
+
plt.ylabel('Gearbox Temperature (°C)')
|
82 |
+
plt.title('Blade Vibration vs. Gearbox Temperature')
|
83 |
+
st.pyplot(plt)
|
84 |
+
st.write("This scatter plot shows the correlation between blade vibration and gearbox temperature. "
|
85 |
+
"High levels of blade vibration can indicate mechanical issues, and this plot helps in identifying "
|
86 |
+
"potential stress on the gearbox due to vibrations.")
|
87 |
+
|
88 |
+
elif graph_type == "Oil Level Distribution":
|
89 |
+
st.write("#### Oil Level Distribution")
|
90 |
+
plt.figure(figsize=(10, 6))
|
91 |
+
plt.hist(data['Oil_Level'], bins=20, color='purple', edgecolor='black')
|
92 |
+
plt.xlabel('Oil Level (%)')
|
93 |
+
plt.ylabel('Frequency')
|
94 |
+
plt.title('Distribution of Oil Level')
|
95 |
+
st.pyplot(plt)
|
96 |
+
st.write("This histogram displays the distribution of oil levels in the turbines. "
|
97 |
+
"Maintaining optimal oil levels is crucial for the smooth operation of turbine components. "
|
98 |
+
"This graph helps in understanding how often turbines operate with low or high oil levels, "
|
99 |
+
"which can impact their reliability and longevity.")
|
100 |
+
|
101 |
+
# Predictive Maintenance
|
102 |
+
st.write("### Predict Equipment Failure")
|
103 |
+
user_input = {
|
104 |
+
'Wind_Speed': st.number_input('Wind Speed (m/s)'),
|
105 |
+
'Ambient_Temperature': st.number_input('Ambient Temperature (°C)'),
|
106 |
+
'Power_Output': st.number_input('Power Output (MW)'),
|
107 |
+
'Blade_Vibration': st.number_input('Blade Vibration (mm/s)'),
|
108 |
+
'Gearbox_Temperature': st.number_input('Gearbox Temperature (°C)'),
|
109 |
+
'Oil_Level': st.number_input('Oil Level (%)'),
|
110 |
+
'Maintenance_History': st.selectbox('Maintenance History (0/1)', [0, 1])
|
111 |
+
}
|
112 |
+
|
113 |
+
input_df = pd.DataFrame([user_input])
|
114 |
+
|
115 |
+
# Load pre-trained model (assumed pre-trained, you should load it here)
|
116 |
+
model = RandomForestClassifier() # This is where you would load your trained model
|
117 |
+
model.fit(data.drop(columns=['Component_Failure', 'Timestamp', 'Turbine_ID']), data['Component_Failure']) # For demonstration only
|
118 |
+
|
119 |
+
prediction = model.predict(input_df)
|
120 |
+
st.write(f"Predicted Component Failure: {'Yes' if prediction[0] == 1 else 'No'}")
|
121 |
+
|
122 |
+
# Intelligent Energy Management Systems
|
123 |
+
elif page == "Intelligent Energy Management Systems":
|
124 |
+
st.header("Intelligent Energy Management Systems")
|
125 |
+
|
126 |
+
# Load the datasets
|
127 |
+
energy_df = load_data('energy_consumption.csv')
|
128 |
+
production_df = load_data('production_schedule.csv')
|
129 |
+
pricing_df = load_data('energy_pricing.csv')
|
130 |
+
|
131 |
+
# Function to display dataset metadata
|
132 |
+
def display_metadata(df, title):
|
133 |
+
st.subheader(f"{title} Metadata")
|
134 |
+
st.write(f"Number of records: {df.shape[0]}")
|
135 |
+
st.write(f"Number of columns: {df.shape[1]}")
|
136 |
+
st.write("Columns:")
|
137 |
+
for col in df.columns:
|
138 |
+
st.write(f"- **{col}**: {df[col].dtype}")
|
139 |
+
|
140 |
+
st.write("""
|
141 |
+
This app demonstrates AI-powered systems that can dynamically manage and allocate energy resources in industrial settings, optimizing energy consumption in real time.
|
142 |
+
""")
|
143 |
+
|
144 |
+
# Display dataset metadata information
|
145 |
+
st.write("### Dataset Metadata Information")
|
146 |
+
|
147 |
+
st.write("""
|
148 |
+
#### Energy Consumption Data:
|
149 |
+
This dataset records the energy consumption of different machines over time, along with associated parameters like temperature, humidity, and operational status.
|
150 |
+
""")
|
151 |
+
display_metadata(energy_df, "Energy Consumption")
|
152 |
+
|
153 |
+
st.write("""
|
154 |
+
#### Production Schedule Data:
|
155 |
+
This dataset contains the production schedules for different machines, including the start and end times of production, the type of product being produced, and the target output.
|
156 |
+
""")
|
157 |
+
display_metadata(production_df, "Production Schedule")
|
158 |
+
|
159 |
+
st.write("""
|
160 |
+
#### Energy Pricing Data:
|
161 |
+
This dataset provides the energy pricing information over time, including indicators for peak hours, which can influence energy consumption optimization strategies.
|
162 |
+
""")
|
163 |
+
display_metadata(pricing_df, "Energy Pricing")
|
164 |
+
|
165 |
+
# Visualization: Energy consumption over time for a selected machine
|
166 |
+
st.header("Energy Consumption Analysis by Machine")
|
167 |
+
|
168 |
+
selected_machine = st.selectbox("Select a Machine ID", energy_df['machine_id'].unique())
|
169 |
+
|
170 |
+
machine_energy_df = energy_df[energy_df['machine_id'] == selected_machine]
|
171 |
+
|
172 |
+
fig, ax = plt.subplots()
|
173 |
+
ax.plot(pd.to_datetime(machine_energy_df['timestamp']), machine_energy_df['energy_consumed_kWh'], label='Energy Consumption (kWh)', color='blue')
|
174 |
+
ax.set_xlabel('Timestamp')
|
175 |
+
ax.set_ylabel('Energy Consumed (kWh)')
|
176 |
+
ax.legend()
|
177 |
+
|
178 |
+
st.pyplot(fig)
|
179 |
+
|
180 |
+
st.write("""
|
181 |
+
This graph shows the energy consumption for the selected machine over time.
|
182 |
+
""")
|
183 |
+
|
184 |
+
# AI-Powered Forecasting
|
185 |
+
st.header("Energy Consumption Forecasting")
|
186 |
+
|
187 |
+
# Prepare the data for Prophet
|
188 |
+
forecast_data = machine_energy_df[['timestamp', 'energy_consumed_kWh']].rename(columns={'timestamp': 'ds', 'energy_consumed_kWh': 'y'})
|
189 |
+
|
190 |
+
# Initialize Prophet model
|
191 |
+
model = Prophet()
|
192 |
+
model.fit(forecast_data)
|
193 |
+
|
194 |
+
# Create future dataframe
|
195 |
+
future = model.make_future_dataframe(periods=48, freq='H') # Forecasting the next 48 hours
|
196 |
+
|
197 |
+
# Forecast
|
198 |
+
forecast = model.predict(future)
|
199 |
+
|
200 |
+
# Plot the forecast
|
201 |
+
st.subheader("Forecasting Results")
|
202 |
+
fig1 = model.plot(forecast)
|
203 |
+
st.pyplot(fig1)
|
204 |
+
|
205 |
+
fig2 = model.plot_components(forecast)
|
206 |
+
st.pyplot(fig2)
|
207 |
+
|
208 |
+
st.write("""
|
209 |
+
The above charts display the forecasted energy consumption for the selected machine over the next 48 hours, along with the trend and seasonality components.
|
210 |
+
""")
|