import gradio as gr import pandas as pd from prophet import Prophet import matplotlib.pyplot as plt def forecast_energy(file): # Read CSV df = pd.read_csv(file) # Rename columns to fit Prophet's expected format df.columns = ['ds', 'y'] # Convert date column to datetime df['ds'] = pd.to_datetime(df['ds']) # Build and train model model = Prophet() model.fit(df) # Forecast next 14 days future = model.make_future_dataframe(periods=14) forecast = model.predict(future) # Plot forecast fig = model.plot(forecast) plt.title("Energy Load Forecast") return fig # Gradio interface demo = gr.Interface( fn=forecast_energy, inputs=gr.File(label="Upload Energy Load CSV", file_types=[".csv"]), outputs=gr.Plot(label="Forecasted Load"), title="Smart Energy Load Forecasting", description="Upload a CSV file with columns 'ds' (date) and 'y' (energy load). This app predicts the next 2 weeks of load." ) if __name__ == "__main__": demo.launch()