jvedsaqib commited on
Commit
bd6c417
·
verified ·
1 Parent(s): 8de2e55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -21,7 +21,6 @@ data_normalized = scaler.fit_transform(data.reshape(-1, 1))
21
 
22
  seq_length = 4
23
 
24
-
25
  class LSTM(nn.Module):
26
  def __init__(self, input_size=INPUT_SIZE, hidden_layer_size=HIDDEN_LAYER_SIZE, output_size=OUTPUT_SIZE):
27
  super(LSTM, self).__init__()
@@ -36,14 +35,17 @@ class LSTM(nn.Module):
36
  predictions = self.linear(lstm_out.view(len(input_seq), -1))
37
  return predictions[-1]
38
 
39
- with open('LSTM_MODEL.pkl', 'rb') as f:
40
- model = pickle.load(f)
41
-
42
  def prepare_custom_input(last_values, seq_length, scaler):
43
  last_values_normalized = scaler.transform(np.array(last_values).reshape(-1, 1))
44
  input_seq = torch.from_numpy(last_values_normalized).float()
45
  return input_seq.view(-1)
46
 
 
 
 
 
 
 
47
  model.eval()
48
 
49
  def predict_and_plot(week1, week2, week3, week4):
 
21
 
22
  seq_length = 4
23
 
 
24
  class LSTM(nn.Module):
25
  def __init__(self, input_size=INPUT_SIZE, hidden_layer_size=HIDDEN_LAYER_SIZE, output_size=OUTPUT_SIZE):
26
  super(LSTM, self).__init__()
 
35
  predictions = self.linear(lstm_out.view(len(input_seq), -1))
36
  return predictions[-1]
37
 
 
 
 
38
  def prepare_custom_input(last_values, seq_length, scaler):
39
  last_values_normalized = scaler.transform(np.array(last_values).reshape(-1, 1))
40
  input_seq = torch.from_numpy(last_values_normalized).float()
41
  return input_seq.view(-1)
42
 
43
+ model_path = 'lstm_model.pth'
44
+
45
+ model = LSTMModel(INPUT_SIZE, HIDDEN_LAYER_SIZE, OUTPUT_SIZE)
46
+
47
+ model.load_state_dict(torch.load(model_path))
48
+
49
  model.eval()
50
 
51
  def predict_and_plot(week1, week2, week3, week4):