-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
138 lines (110 loc) · 3.99 KB
/
Copy pathmain.py
File metadata and controls
138 lines (110 loc) · 3.99 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
AI Chat Log Converter - Main Entry Point
License: MIT
Unified entry point for AI Chat Log Converter.
Provides options to launch either the web interface or command-line interface.
Usage:
python main.py # Launch web interface (default)
python main.py --web # Launch web interface explicitly
python main.py --cli # Launch command-line interface
python main.py --help # Show help information
"""
import argparse
import sys
def print_banner():
"""Print application banner."""
banner = """
╔═══════════════════════════════════════════════════════════╗
║ ║
║ 🤖 AI Chat Log Converter v1.0.0 ║
║ ║
║ Process and transform AI chat logs ║
║ Group by Agent · Local Processing · Privacy Safe ║
║ ║
╚═══════════════════════════════════════════════════════════╝
"""
print(banner)
def launch_web(port: int = 8010):
"""Launch the web interface using FastAPI + Uvicorn."""
print("🚀 Launching Web Interface...")
print(f"📍 URL: http://127.0.0.1:{port}")
print(f"📖 API Docs: http://127.0.0.1:{port}/api/docs")
print("⏹️ Press Ctrl+C to stop\n")
try:
import uvicorn
from api import app
uvicorn.run(
app,
host="127.0.0.1",
port=port,
log_level="info"
)
except ImportError:
print("❌ Error: Required packages not installed.")
print("💡 Please run: pip install fastapi uvicorn python-multipart")
sys.exit(1)
except KeyboardInterrupt:
print("\n👋 Web interface stopped.")
sys.exit(0)
def launch_cli():
"""Launch the command-line interface."""
print("💻 Launching Command-Line Interface...\n")
try:
from cli import main as cli_main
cli_main()
except ImportError:
print("❌ Error: CLI module not found.")
sys.exit(1)
except SystemExit as e:
sys.exit(e.code if e.code else 0)
def create_parser() -> argparse.ArgumentParser:
"""Create argument parser for main entry point."""
parser = argparse.ArgumentParser(
prog='chatlog-converter',
description='🤖 AI Chat Log Converter - Choose your interface\n',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python main.py Launch web interface (default)
python main.py --web Launch web interface explicitly
python main.py --cli Launch command-line interface
python main.py --port 9000 Launch web on custom port
""",
add_help=True
)
parser.add_argument(
'--web', '-w',
action='store_true',
default=False,
help='Launch web interface (default)'
)
parser.add_argument(
'--cli', '-c',
action='store_true',
default=False,
help='Launch command-line interface'
)
parser.add_argument(
'--port', '-p',
type=int,
default=8010,
help='Port for web interface (default: 8010)'
)
return parser
def main():
"""Main entry point with interface selection."""
print_banner()
parser = create_parser()
args = parser.parse_args()
# If no arguments provided, default to web interface
if not args.web and not args.cli:
print("ℹ️ No mode specified, launching web interface by default.\n")
launch_web(args.port)
return
# Launch selected interface
if args.cli:
launch_cli()
else:
launch_web(args.port)
if __name__ == '__main__':
main()