munem420 commited on
Commit
bf9afc7
·
verified ·
1 Parent(s): 53427fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -7
app.py CHANGED
@@ -7,10 +7,8 @@ import pandas as pd
7
  import yfinance as yf
8
  from huggingface_hub import hf_hub_download
9
 
10
- # This forces TensorFlow to only use the CPU.
11
  os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
12
 
13
- # --- 1. Download Model and Scalers from Hugging Face Hub ---
14
  MODEL_REPO = "munem420/stock-forecaster-lstm"
15
  MODEL_FILENAME = "model_lstm.h5"
16
  SCALER_FILENAME = "scalers.joblib"
@@ -24,13 +22,11 @@ except Exception as e:
24
  print(f"❌ Error downloading files: {e}")
25
  model_path, scalers_path = None, None
26
 
27
- # --- 2. Load the Model and Scalers ---
28
  loaded_model_lstm = None
29
  loaded_scalers = None
30
 
31
  if model_path and os.path.exists(model_path):
32
  try:
33
- # FIX #1: Added custom_objects to handle the 'mse' metric during loading
34
  loaded_model_lstm = tf.keras.models.load_model(
35
  model_path,
36
  custom_objects={"mse": tf.keras.losses.MeanSquaredError()}
@@ -46,8 +42,6 @@ if scalers_path and os.path.exists(scalers_path):
46
  except Exception as e:
47
  print(f"❌ Error loading scalers: {e}")
48
 
49
- # ... (The rest of the file is unchanged) ...
50
-
51
  ticker_to_name = {'ZURVY': 'Zurich Insurance Group AG'}
52
 
53
  def get_ticker_from_input(input_name):
@@ -69,7 +63,7 @@ def forecast_stock(input_name, model, scalers_dict, input_width=60):
69
  if len(data_df) < input_width:
70
  return f"Error: Not enough historical data. Need {input_width} days, but only have {len(data_df)}."
71
  recent_data = data_df.tail(input_width)
72
- close_prices = recent_data['Close'].values.reshape(-1, 1)
73
  scaler = scalers_dict.get(ticker)
74
  if not scaler:
75
  print(f"Warning: No specific scaler found for {ticker}. Using ZURVY's scaler as a fallback.")
 
7
  import yfinance as yf
8
  from huggingface_hub import hf_hub_download
9
 
 
10
  os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
11
 
 
12
  MODEL_REPO = "munem420/stock-forecaster-lstm"
13
  MODEL_FILENAME = "model_lstm.h5"
14
  SCALER_FILENAME = "scalers.joblib"
 
22
  print(f"❌ Error downloading files: {e}")
23
  model_path, scalers_path = None, None
24
 
 
25
  loaded_model_lstm = None
26
  loaded_scalers = None
27
 
28
  if model_path and os.path.exists(model_path):
29
  try:
 
30
  loaded_model_lstm = tf.keras.models.load_model(
31
  model_path,
32
  custom_objects={"mse": tf.keras.losses.MeanSquaredError()}
 
42
  except Exception as e:
43
  print(f"❌ Error loading scalers: {e}")
44
 
 
 
45
  ticker_to_name = {'ZURVY': 'Zurich Insurance Group AG'}
46
 
47
  def get_ticker_from_input(input_name):
 
63
  if len(data_df) < input_width:
64
  return f"Error: Not enough historical data. Need {input_width} days, but only have {len(data_df)}."
65
  recent_data = data_df.tail(input_width)
66
+ close_prices = recent_data['Close'].values.reshape(-input, 1)
67
  scaler = scalers_dict.get(ticker)
68
  if not scaler:
69
  print(f"Warning: No specific scaler found for {ticker}. Using ZURVY's scaler as a fallback.")