|
import gradio as gr |
|
import numpy as np |
|
import tensorflow as tf |
|
from tensorflow.keras.models import load_model |
|
from sklearn.preprocessing import MinMaxScaler |
|
|
|
|
|
model = load_model('lstm_model') |
|
|
|
|
|
scaler = MinMaxScaler(feature_range=(0, 1)) |
|
|
|
|
|
def predict_sales(input_data): |
|
|
|
input_data = np.array(input_data).reshape(1, 30, 1) |
|
scaled_input = scaler.transform(input_data) |
|
|
|
|
|
prediction = model.predict(scaled_input) |
|
actual_prediction = scaler.inverse_transform(prediction) |
|
|
|
return actual_prediction[0][0] |
|
|
|
|
|
inputs = gr.inputs.Dataframe(headers=["Sales"], type="numpy", row_count=30, col_count=1) |
|
outputs = gr.outputs.Textbox() |
|
|
|
interface = gr.Interface(fn=predict_sales, inputs=inputs, outputs=outputs, title="LSTM Sales Forecasting") |
|
interface.launch() |
|
|