-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·75 lines (62 loc) · 2.15 KB
/
main.py
File metadata and controls
executable file
·75 lines (62 loc) · 2.15 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
#!/usr/bin/env python3
"""
AI Image Generation - CLI Interface Principal
Permite gerar imagens com IA através da linha de comando
Última atualização: 3 de setembro de 2025
"""
import os
import sys
import argparse
import logging
from dotenv import load_dotenv
from pathlib import Path
# Configurar logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger("ai-image")
# Carregar variáveis de ambiente
load_dotenv()
# Adicionar diretório raiz ao path
root_dir = Path(__file__).parent
sys.path.append(str(root_dir))
# Importar CLI da aplicação
from src.cli import cli as app_cli
def setup_environment():
"""Configurar o ambiente antes de executar"""
# Criar diretórios necessários se não existirem
output_dir = os.getenv("AI_IMAGE_OUTPUT_DIR", "output")
cache_dir = os.getenv("AI_IMAGE_CACHE_DIR", ".cache")
logs_dir = os.getenv("AI_IMAGE_LOGS_DIR", "logs")
for directory in [output_dir, cache_dir, logs_dir]:
Path(directory).mkdir(exist_ok=True)
# Verificar existência do arquivo .env
if not Path(".env").exists():
logger.warning("Arquivo .env não encontrado. Usando valores padrão.")
if Path(".env.example").exists():
logger.info("Considere copiar .env.example para .env e configurar.")
def main():
"""Função principal do CLI"""
parser = argparse.ArgumentParser(
description="AI Image Generation Service CLI",
epilog="Use --help com qualquer subcomando para ver opções detalhadas"
)
# Subcomandos disponíveis
parser.add_argument(
"--version",
action="version",
version=f"AI Image Generation v{os.getenv('AI_IMAGE_APP_VERSION', '1.0.0')}"
)
# Se executado diretamente sem argumentos, invocar a CLI completa
if len(sys.argv) == 1:
app_cli()
else:
# Parse args e passa para o CLI principal
parser.parse_args() # Apenas para exibir mensagens de erro caso necessário
app_cli()
if __name__ == "__main__":
# Configurar ambiente
setup_environment()
# Executar CLI
main()