ranjeetjb commited on
Commit
326c101
·
verified ·
1 Parent(s): 037e45e

create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow.keras.models import load_model
5
+ from sklearn.preprocessing import MinMaxScaler
6
+
7
+ # Load the saved model
8
+ model = load_model('lstm_model')
9
+
10
+ # Dummy scaler (replace this with the actual scaler used in training)
11
+ scaler = MinMaxScaler(feature_range=(0, 1))
12
+
13
+ # Function for Prediction
14
+ def predict_sales(input_data):
15
+ # Reshape and scale input data
16
+ input_data = np.array(input_data).reshape(1, 30, 1)
17
+ scaled_input = scaler.transform(input_data)
18
+
19
+ # Predict
20
+ prediction = model.predict(scaled_input)
21
+ actual_prediction = scaler.inverse_transform(prediction)
22
+
23
+ return actual_prediction[0][0]
24
+
25
+ # Gradio Interface
26
+ inputs = gr.inputs.Dataframe(headers=["Sales"], type="numpy", row_count=30, col_count=1)
27
+ outputs = gr.outputs.Textbox()
28
+
29
+ interface = gr.Interface(fn=predict_sales, inputs=inputs, outputs=outputs, title="LSTM Sales Forecasting")
30
+ interface.launch()