Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime, timedelta
|
|
@@ -6,7 +5,6 @@ from prophet import Prophet
|
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
-
# Simulate factory sensor data
|
| 10 |
def simulate_factory_data(days=30, freq='H'):
|
| 11 |
date_rng = pd.date_range(end=datetime.now(), periods=24 * days, freq=freq)
|
| 12 |
df = pd.DataFrame(date_rng, columns=['ds'])
|
|
@@ -15,16 +13,13 @@ def simulate_factory_data(days=30, freq='H'):
|
|
| 15 |
df['power_usage'] = np.random.normal(loc=120, scale=10, size=(len(date_rng)))
|
| 16 |
return df
|
| 17 |
|
| 18 |
-
# Forecast temperature using Prophet
|
| 19 |
def forecast_temperature(days):
|
| 20 |
df = simulate_factory_data()
|
| 21 |
model = Prophet()
|
| 22 |
df_temp = df[['ds', 'temperature']].rename(columns={"temperature": "y"})
|
| 23 |
model.fit(df_temp)
|
| 24 |
-
|
| 25 |
future = model.make_future_dataframe(periods=days, freq='H')
|
| 26 |
forecast = model.predict(future)
|
| 27 |
-
|
| 28 |
fig, ax = plt.subplots(figsize=(10, 5))
|
| 29 |
ax.plot(df['ds'], df['temperature'], label='Actual')
|
| 30 |
ax.plot(forecast['ds'], forecast['yhat'], label='Forecast')
|
|
@@ -36,12 +31,11 @@ def forecast_temperature(days):
|
|
| 36 |
plt.tight_layout()
|
| 37 |
return fig
|
| 38 |
|
| 39 |
-
# Gradio Interface
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=forecast_temperature,
|
| 42 |
inputs=gr.Slider(12, 72, value=48, label="Forecast Hours"),
|
| 43 |
outputs=gr.Plot(label="Forecasted Temperature Chart"),
|
| 44 |
-
title="Smart Factory AI Pipeline",
|
| 45 |
description="Simulated machine temperature forecasting using Prophet. Drag the slider to choose how far to forecast."
|
| 46 |
)
|
| 47 |
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import numpy as np
|
| 3 |
from datetime import datetime, timedelta
|
|
|
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
import gradio as gr
|
| 7 |
|
|
|
|
| 8 |
def simulate_factory_data(days=30, freq='H'):
|
| 9 |
date_rng = pd.date_range(end=datetime.now(), periods=24 * days, freq=freq)
|
| 10 |
df = pd.DataFrame(date_rng, columns=['ds'])
|
|
|
|
| 13 |
df['power_usage'] = np.random.normal(loc=120, scale=10, size=(len(date_rng)))
|
| 14 |
return df
|
| 15 |
|
|
|
|
| 16 |
def forecast_temperature(days):
|
| 17 |
df = simulate_factory_data()
|
| 18 |
model = Prophet()
|
| 19 |
df_temp = df[['ds', 'temperature']].rename(columns={"temperature": "y"})
|
| 20 |
model.fit(df_temp)
|
|
|
|
| 21 |
future = model.make_future_dataframe(periods=days, freq='H')
|
| 22 |
forecast = model.predict(future)
|
|
|
|
| 23 |
fig, ax = plt.subplots(figsize=(10, 5))
|
| 24 |
ax.plot(df['ds'], df['temperature'], label='Actual')
|
| 25 |
ax.plot(forecast['ds'], forecast['yhat'], label='Forecast')
|
|
|
|
| 31 |
plt.tight_layout()
|
| 32 |
return fig
|
| 33 |
|
|
|
|
| 34 |
demo = gr.Interface(
|
| 35 |
fn=forecast_temperature,
|
| 36 |
inputs=gr.Slider(12, 72, value=48, label="Forecast Hours"),
|
| 37 |
outputs=gr.Plot(label="Forecasted Temperature Chart"),
|
| 38 |
+
title="Smart Factory AI Pipeline by Aryan",
|
| 39 |
description="Simulated machine temperature forecasting using Prophet. Drag the slider to choose how far to forecast."
|
| 40 |
)
|
| 41 |
|