Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (66 loc) · 2.29 KB
/
Copy pathmain.py
File metadata and controls
80 lines (66 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import argparse
import logging
import pathlib
import sys
import matplotlib
from src.config import load_config
from src.orchestrator import run_generation_process
def run_cli():
"""Runs the command-line book generation process."""
# Load configuration
config = load_config()
debug_options = config.get("debug_options", {})
log_output_path = debug_options.get("log_output_path")
# Configure logging
log_handlers = [logging.StreamHandler(sys.stdout)]
if log_output_path:
try:
log_dir = pathlib.Path(log_output_path).parent
log_dir.mkdir(parents=True, exist_ok=True)
log_handlers.append(logging.FileHandler(log_output_path, mode="w"))
except Exception as e:
# Can't use logger here.
print(
f"Failed to configure file logging: {e}. "
f"Falling back to console logging.",
file=sys.stderr,
)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=log_handlers,
force=True,
)
logging.info("Starting book generation process from CLI...")
run_generation_process()
logging.info("Book generation process finished.")
def main():
"""Main entry point for the application."""
parser = argparse.ArgumentParser(description="LLM Book Generator")
parser.add_argument(
"--cli", action="store_true", help="Run in command-line interface mode."
)
args = parser.parse_args()
# Configure Matplotlib to use LaTeX and load amsmath
matplotlib.rcParams["text.usetex"] = True
matplotlib.rcParams["text.latex.preamble"] = (
r"\usepackage{amsmath} \usepackage{amssymb}"
)
# Ensure matplotlib doesn't try to use a GUI backend
matplotlib.pyplot.switch_backend("Agg")
if args.cli:
run_cli()
else:
# Run the GUI application
try:
from gui import main as run_gui
run_gui()
except ImportError as e:
print(f"Could not import GUI components: {e}", file=sys.stderr)
print(
"Please ensure PySide6 is installed (`pip install PySide6`).",
file=sys.stderr,
)
sys.exit(1)
if __name__ == "__main__":
main()