Skip to content

Commit 4c89e4b

Browse files
committed
Made ideeplc core compatible with GUI
Add another logging to show in terminal behind gui. Changed model path for gui
1 parent fe08cc4 commit 4c89e4b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

ideeplc/ideeplc_core.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import logging
33
import torch
44
from pathlib import Path
5+
import sys
56
from torch import nn
7+
import os
68
from torch.utils.data import DataLoader
79
from ideeplc.model import MyNet
810
from ideeplc.config import get_config
@@ -15,7 +17,20 @@
1517
# Logging configuration
1618
LOGGER = logging.getLogger(__name__)
1719

20+
def setup_logging():
21+
log_dir = Path("logs")
22+
log_dir.mkdir(exist_ok=True)
1823

24+
file_handler = logging.FileHandler(log_dir / "ideeplc.log")
25+
console_handler = logging.StreamHandler()
26+
27+
logging.basicConfig(
28+
level=logging.INFO,
29+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
30+
handlers=[file_handler, console_handler]
31+
)
32+
33+
setup_logging()
1934
def get_model_save_path():
2035
"""
2136
Determines the correct directory and filename for saving the model.
@@ -26,10 +41,18 @@ def get_model_save_path():
2641
tuple: (model_save_path, model_dir)
2742
"""
2843
timestamp = datetime.datetime.now().strftime("%m%d")
29-
model_dir = Path(f"ideeplc/models/{timestamp}")
30-
pretrained_path = files("ideeplc.models").joinpath("pretrained_model.pth")
44+
model_dir = Path("ideeplc/models") / timestamp
3145
model_name = "pretrained_model.pth"
32-
return model_dir / model_name, model_dir, pretrained_path
46+
47+
if getattr(sys, "frozen", False):
48+
# If frozen (PyInstaller)
49+
base_path = Path(sys._MEIPASS)
50+
model_path = base_path / "ideeplc" / "models" / model_name
51+
else:
52+
# If normal Python environment
53+
model_path = files("ideeplc.models").joinpath(model_name)
54+
55+
return model_path, model_dir, model_path
3356

3457

3558
def main(args):

0 commit comments

Comments
 (0)