File size: 2,254 Bytes
26bead7
 
 
cc7a977
 
26bead7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc7a977
 
 
 
 
 
 
 
7c518e6
 
 
 
 
 
 
26bead7
 
 
 
 
 
17b6e64
26bead7
 
17b6e64
 
26bead7
7c518e6
26bead7
 
 
 
 
 
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
"""Main entrypoint module for the AI Python C Extensions Generator application."""

from logging import getLogger
from os import getenv, sep
from pathlib import Path
from sys import platform

from .compiler import compile_extension
from .interface import get_interface
from .optimizer import optimize_gpt as optimize_function
from .tester import test_extension


_logger = getLogger(__name__)

# Default models list
DEFAULT_MODELS = ["gpt-5.1-codex", "gpt-5.4"]  # Expensive.
DEFAULT_MODELS = ["gpt-5.1-codex-mini", "gpt-5.4-mini"]  # Cheap.

# Read available models from environment variable or use defaults
models = models_env.split(":") if (models_env := getenv("MODELS")) else DEFAULT_MODELS

# Detect system platform for default selection.
if platform == "win32":
    default_platform = "Windows"
else:
    default_platform = "Linux"

# Read compile stage flag from environment variable, defaulting to False if not set.
if compile_stage := getenv("COMPILE_STAGE", "False").lower() in ("true", "1", "yes"):
    # Define the build directory for compiled extensions.
    BUILD_DIR = Path("compiled")
    # BUILD_DIR.mkdir(parents=True, exist_ok=True)
    _logger.info('COMPILE STAGE ENABLED')
    _logger.info(f'COMPILE DIRECTORY SET TO: .{sep}{BUILD_DIR}')


# CSS styles for the interface, defining background colors for C and Python code areas.
css = """
.c_ext {background-color: #050;}
.python {background-color: #306998;}
"""


def main():
    """Launch the AI Python C Extensions Generator application."""
    _logger.info('STARTING AI PYTHON C EXTENSIONS GENERATOR...')
    _logger.info(f'AVAILABLE MODELS: {models}')
    # Prepare the interface configuration based.
    interface_config = {"models": models, "compile_stage": compile_stage,
                        "optimize_function": optimize_function}
    if compile_stage:
        interface_config.update({"compile_extension": compile_extension,
                                 "test_extension": test_extension,
                                 "compile_path": BUILD_DIR})
    app = get_interface(**interface_config)
    app.launch(footer_links=[], css=css)
    # We return the app instance for potential use in autoreload scenarios.
    return app


if __name__ == '__main__':
    main()