File size: 950 Bytes
326c101 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
from sklearn.preprocessing import MinMaxScaler
# Load the saved model
model = load_model('lstm_model')
# Dummy scaler (replace this with the actual scaler used in training)
scaler = MinMaxScaler(feature_range=(0, 1))
# Function for Prediction
def predict_sales(input_data):
# Reshape and scale input data
input_data = np.array(input_data).reshape(1, 30, 1)
scaled_input = scaler.transform(input_data)
# Predict
prediction = model.predict(scaled_input)
actual_prediction = scaler.inverse_transform(prediction)
return actual_prediction[0][0]
# Gradio Interface
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()
|