Download model if needed and start interactive chat.
(args)
| 1019 | |
| 1020 | |
| 1021 | def cmd_run(args): |
| 1022 | """Download model if needed and start interactive chat.""" |
| 1023 | from .config_utils import CactusConfig |
| 1024 | |
| 1025 | config = CactusConfig() |
| 1026 | api_key = prompt_for_api_key(config) |
| 1027 | |
| 1028 | if api_key: |
| 1029 | os.environ["CACTUS_CLOUD_KEY"] = api_key |
| 1030 | |
| 1031 | model_id = args.model_id |
| 1032 | |
| 1033 | if getattr(args, 'no_cloud_tele', False): |
| 1034 | os.environ["CACTUS_NO_CLOUD_TELE"] = "1" |
| 1035 | |
| 1036 | lib_path = PROJECT_ROOT / "cactus" / "build" / "libcactus.a" |
| 1037 | if not lib_path.exists(): |
| 1038 | print_color(RED, "Error: Cactus library not built. Run 'cactus build' first.") |
| 1039 | return 1 |
| 1040 | |
| 1041 | local_path = Path(model_id) |
| 1042 | if local_path.exists() and (local_path / "config.txt").exists(): |
| 1043 | weights_dir = local_path |
| 1044 | print_color(GREEN, f"Using local model: {weights_dir}") |
| 1045 | else: |
| 1046 | download_result = cmd_download(args) |
| 1047 | if download_result != 0: |
| 1048 | return download_result |
| 1049 | weights_dir = get_effective_weights_dir(model_id, args) |
| 1050 | |
| 1051 | image_path = getattr(args, 'image', None) |
| 1052 | if image_path: |
| 1053 | image_path = str(Path(image_path).resolve()) |
| 1054 | if not Path(image_path).exists(): |
| 1055 | print_color(RED, f"Error: Image file not found: {image_path}") |
| 1056 | return 1 |
| 1057 | valid_exts = {'.png', '.jpg', '.jpeg', '.bmp'} |
| 1058 | if Path(image_path).suffix.lower() not in valid_exts: |
| 1059 | print_color(RED, f"Error: Unsupported image format. Supported: {', '.join(valid_exts)}") |
| 1060 | return 1 |
| 1061 | |
| 1062 | try: |
| 1063 | chat_binary = _ensure_chat_binary(PROJECT_ROOT, lib_path) |
| 1064 | except RuntimeError as exc: |
| 1065 | print_color(RED, f"Error: {exc}") |
| 1066 | return 1 |
| 1067 | |
| 1068 | os.system('clear' if platform.system() != 'Windows' else 'cls') |
| 1069 | print_color(GREEN, f"Starting Cactus Chat with model: {model_id}") |
| 1070 | print() |
| 1071 | |
| 1072 | audio_path = getattr(args, 'audio', None) |
| 1073 | if audio_path: |
| 1074 | audio_path = str(Path(audio_path).resolve()) |
| 1075 | if not Path(audio_path).exists(): |
| 1076 | print_color(RED, f"Error: Audio file not found: {audio_path}") |
| 1077 | return 1 |
| 1078 |
no test coverage detected