Spaces:
Runtime error
Runtime error
amitke commited on
Commit ·
457b70c
1
Parent(s): c820a87
- app.py +1 -0
- inference.py +3 -1
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from train import train as train_fn
|
|
| 4 |
from testing import evaluate as eval_fn
|
| 5 |
from inference import predict_next as predict_fn
|
| 6 |
|
|
|
|
| 7 |
def train_api(symbol, seq_len=60, epochs=5, batch_size=32, start="", end=""):
|
| 8 |
return train_fn(
|
| 9 |
symbol,
|
|
|
|
| 4 |
from testing import evaluate as eval_fn
|
| 5 |
from inference import predict_next as predict_fn
|
| 6 |
|
| 7 |
+
@spaces.GPU
|
| 8 |
def train_api(symbol, seq_len=60, epochs=5, batch_size=32, start="", end=""):
|
| 9 |
return train_fn(
|
| 10 |
symbol,
|
inference.py
CHANGED
|
@@ -8,6 +8,7 @@ from models import StockLSTM
|
|
| 8 |
|
| 9 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 10 |
ARTIFACTS_DIR = "artifacts"
|
|
|
|
| 11 |
|
| 12 |
def _paths(symbol: str):
|
| 13 |
base = os.path.join(ARTIFACTS_DIR, symbol.upper())
|
|
@@ -27,7 +28,8 @@ def _load_artifacts(symbol: str):
|
|
| 27 |
scaler = pickle.load(f)
|
| 28 |
|
| 29 |
model = StockLSTM(input_dim=1, hidden_dim=64, num_layers=2, dropout=0.2)
|
| 30 |
-
model
|
|
|
|
| 31 |
model.eval()
|
| 32 |
return model, scaler, meta
|
| 33 |
|
|
|
|
| 8 |
|
| 9 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 10 |
ARTIFACTS_DIR = "artifacts"
|
| 11 |
+
device = torch.device("cpu")
|
| 12 |
|
| 13 |
def _paths(symbol: str):
|
| 14 |
base = os.path.join(ARTIFACTS_DIR, symbol.upper())
|
|
|
|
| 28 |
scaler = pickle.load(f)
|
| 29 |
|
| 30 |
model = StockLSTM(input_dim=1, hidden_dim=64, num_layers=2, dropout=0.2)
|
| 31 |
+
model = model.to(device)
|
| 32 |
+
model.load_state_dict(torch.load(p["model"], map_location="cpu"))
|
| 33 |
model.eval()
|
| 34 |
return model, scaler, meta
|
| 35 |
|