Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from sklearn.ensemble import RandomForestClassifier | |
from prophet import Prophet | |
# Load dataset | |
def load_data(filename): | |
return pd.read_csv(filename) | |
# Main application | |
st.sidebar.title("AI-Powered Industrial Management") | |
page = st.sidebar.radio("Choose a page", ["Predictive Maintenance for Wind Turbines", "Intelligent Energy Management Systems"]) | |
# Predictive Maintenance for Wind Turbines | |
if page == "Predictive Maintenance for Wind Turbines": | |
st.header("Predictive Maintenance for Wind Turbines") | |
# Load and display dataset | |
data = load_data('wind_turbine_data.csv') | |
st.write("### Dataset Preview:") | |
st.write(data.head()) | |
# Dataset Meta Information | |
st.write("### Dataset Meta Information:") | |
st.write(""" | |
- **Timestamp:** The time at which the data was recorded. | |
- **Turbine_ID:** Unique identifier for each wind turbine. | |
- **Wind_Speed (m/s):** The speed of the wind at the time of measurement. | |
- **Ambient_Temperature (°C):** The outside temperature where the turbine is located. | |
- **Power_Output (MW):** The power generated by the turbine at the time of measurement. | |
- **Blade_Vibration (mm/s):** The vibration level of the turbine blades, a critical indicator of potential mechanical issues. | |
- **Gearbox_Temperature (°C):** Temperature inside the turbine's gearbox. | |
- **Oil_Level (%):** The level of lubrication oil in the turbine. | |
- **Maintenance_History (0/1):** Whether the turbine underwent maintenance in the last 30 days (1) or not (0). | |
- **Component_Failure (0/1):** Whether a component failure occurred (1) or not. This is the target variable. | |
""") | |
# Data Exploration | |
st.write("### Data Exploration") | |
# Select Graph Type | |
graph_type = st.selectbox("Select a graph to visualize:", | |
["Wind Speed Distribution", | |
"Ambient Temperature vs. Power Output", | |
"Blade Vibration vs. Gearbox Temperature", | |
"Oil Level Distribution"]) | |
# Plotting based on selection | |
if graph_type == "Wind Speed Distribution": | |
st.write("#### Wind Speed Distribution") | |
plt.figure(figsize=(10, 6)) | |
plt.hist(data['Wind_Speed'], bins=20, color='skyblue', edgecolor='black') | |
plt.xlabel('Wind Speed (m/s)') | |
plt.ylabel('Frequency') | |
plt.title('Distribution of Wind Speed') | |
st.pyplot(plt) | |
st.write("This graph shows the distribution of wind speeds recorded in the dataset. " | |
"It helps in understanding the common wind speeds at which the turbines operate, " | |
"which can be crucial for assessing turbine performance and predicting failures.") | |
elif graph_type == "Ambient Temperature vs. Power Output": | |
st.write("#### Ambient Temperature vs. Power Output") | |
plt.figure(figsize=(10, 6)) | |
plt.scatter(data['Ambient_Temperature'], data['Power_Output'], color='green', alpha=0.6) | |
plt.xlabel('Ambient Temperature (°C)') | |
plt.ylabel('Power Output (MW)') | |
plt.title('Ambient Temperature vs. Power Output') | |
st.pyplot(plt) | |
st.write("This scatter plot illustrates the relationship between ambient temperature and power output. " | |
"It shows how temperature variations can affect the power generated by the wind turbines, " | |
"which is important for understanding operational efficiency under different weather conditions.") | |
elif graph_type == "Blade Vibration vs. Gearbox Temperature": | |
st.write("#### Blade Vibration vs. Gearbox Temperature") | |
plt.figure(figsize=(10, 6)) | |
plt.scatter(data['Blade_Vibration'], data['Gearbox_Temperature'], color='orange', alpha=0.6) | |
plt.xlabel('Blade Vibration (mm/s)') | |
plt.ylabel('Gearbox Temperature (°C)') | |
plt.title('Blade Vibration vs. Gearbox Temperature') | |
st.pyplot(plt) | |
st.write("This scatter plot shows the correlation between blade vibration and gearbox temperature. " | |
"High levels of blade vibration can indicate mechanical issues, and this plot helps in identifying " | |
"potential stress on the gearbox due to vibrations.") | |
elif graph_type == "Oil Level Distribution": | |
st.write("#### Oil Level Distribution") | |
plt.figure(figsize=(10, 6)) | |
plt.hist(data['Oil_Level'], bins=20, color='purple', edgecolor='black') | |
plt.xlabel('Oil Level (%)') | |
plt.ylabel('Frequency') | |
plt.title('Distribution of Oil Level') | |
st.pyplot(plt) | |
st.write("This histogram displays the distribution of oil levels in the turbines. " | |
"Maintaining optimal oil levels is crucial for the smooth operation of turbine components. " | |
"This graph helps in understanding how often turbines operate with low or high oil levels, " | |
"which can impact their reliability and longevity.") | |
# Predictive Maintenance | |
st.write("### Predict Equipment Failure") | |
user_input = { | |
'Wind_Speed': st.number_input('Wind Speed (m/s)'), | |
'Ambient_Temperature': st.number_input('Ambient Temperature (°C)'), | |
'Power_Output': st.number_input('Power Output (MW)'), | |
'Blade_Vibration': st.number_input('Blade Vibration (mm/s)'), | |
'Gearbox_Temperature': st.number_input('Gearbox Temperature (°C)'), | |
'Oil_Level': st.number_input('Oil Level (%)'), | |
'Maintenance_History': st.selectbox('Maintenance History (0/1)', [0, 1]) | |
} | |
input_df = pd.DataFrame([user_input]) | |
# Load pre-trained model (assumed pre-trained, you should load it here) | |
model = RandomForestClassifier() # This is where you would load your trained model | |
model.fit(data.drop(columns=['Component_Failure', 'Timestamp', 'Turbine_ID']), data['Component_Failure']) # For demonstration only | |
prediction = model.predict(input_df) | |
st.write(f"Predicted Component Failure: {'Yes' if prediction[0] == 1 else 'No'}") | |
# Intelligent Energy Management Systems | |
elif page == "Intelligent Energy Management Systems": | |
st.header("Intelligent Energy Management Systems") | |
# Load the datasets | |
energy_df = load_data('energy_consumption.csv') | |
production_df = load_data('production_schedule.csv') | |
pricing_df = load_data('energy_pricing.csv') | |
# Function to display dataset metadata | |
def display_metadata(df, title): | |
st.subheader(f"{title} Metadata") | |
st.write(f"Number of records: {df.shape[0]}") | |
st.write(f"Number of columns: {df.shape[1]}") | |
st.write("Columns:") | |
for col in df.columns: | |
st.write(f"- **{col}**: {df[col].dtype}") | |
st.write(""" | |
This app demonstrates AI-powered systems that can dynamically manage and allocate energy resources in industrial settings, optimizing energy consumption in real time. | |
""") | |
# Display dataset metadata information | |
st.write("### Dataset Metadata Information") | |
st.write(""" | |
#### Energy Consumption Data: | |
This dataset records the energy consumption of different machines over time, along with associated parameters like temperature, humidity, and operational status. | |
""") | |
display_metadata(energy_df, "Energy Consumption") | |
st.write(""" | |
#### Production Schedule Data: | |
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. | |
""") | |
display_metadata(production_df, "Production Schedule") | |
st.write(""" | |
#### Energy Pricing Data: | |
This dataset provides the energy pricing information over time, including indicators for peak hours, which can influence energy consumption optimization strategies. | |
""") | |
display_metadata(pricing_df, "Energy Pricing") | |
# Visualization: Energy consumption over time for a selected machine | |
st.header("Energy Consumption Analysis by Machine") | |
selected_machine = st.selectbox("Select a Machine ID", energy_df['machine_id'].unique()) | |
machine_energy_df = energy_df[energy_df['machine_id'] == selected_machine] | |
fig, ax = plt.subplots() | |
ax.plot(pd.to_datetime(machine_energy_df['timestamp']), machine_energy_df['energy_consumed_kWh'], label='Energy Consumption (kWh)', color='blue') | |
ax.set_xlabel('Timestamp') | |
ax.set_ylabel('Energy Consumed (kWh)') | |
ax.legend() | |
st.pyplot(fig) | |
st.write(""" | |
This graph shows the energy consumption for the selected machine over time. | |
""") | |
# AI-Powered Forecasting | |
st.header("Energy Consumption Forecasting") | |
# Prepare the data for Prophet | |
forecast_data = machine_energy_df[['timestamp', 'energy_consumed_kWh']].rename(columns={'timestamp': 'ds', 'energy_consumed_kWh': 'y'}) | |
# Initialize Prophet model | |
model = Prophet() | |
model.fit(forecast_data) | |
# Create future dataframe | |
future = model.make_future_dataframe(periods=48, freq='H') # Forecasting the next 48 hours | |
# Forecast | |
forecast = model.predict(future) | |
# Plot the forecast | |
st.subheader("Forecasting Results") | |
fig1 = model.plot(forecast) | |
st.pyplot(fig1) | |
fig2 = model.plot_components(forecast) | |
st.pyplot(fig2) | |
st.write(""" | |
The above charts display the forecasted energy consumption for the selected machine over the next 48 hours, along with the trend and seasonality components. | |
""") | |