File size: 3,599 Bytes
c7e9f96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c36d41e
 
 
 
 
 
 
 
 
 
 
c7e9f96
 
 
 
 
 
c36d41e
 
 
 
 
 
 
 
 
 
 
 
c7e9f96
 
 
 
 
c36d41e
 
c7e9f96
 
 
 
 
 
 
 
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
"""
Hugging Face Spaces์šฉ Flask ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ง„์ž…์ 
"""
import sys
import os
import logging
from logging.handlers import RotatingFileHandler

# UTF-8 ์ธ์ฝ”๋”ฉ ๊ฐ•์ œ ์„ค์ •
if sys.platform == 'win32':
    sys.stdout.reconfigure(encoding='utf-8')
    sys.stderr.reconfigure(encoding='utf-8')

from app import create_app

app = create_app()

# Hugging Face Spaces ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
# Spaces๋Š” ์ž๋™์œผ๋กœ ํฌํŠธ๋ฅผ ํ• ๋‹นํ•˜๋ฏ€๋กœ ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ๊ฐ€์ ธ์˜ด
port = int(os.environ.get('PORT', 7860))
host = os.environ.get('HOST', '0.0.0.0')

# ๋กœ๊น… ์„ค์ •
if not os.path.exists('logs'):
    os.mkdir('logs')

# ํŒŒ์ผ ํ•ธ๋“ค๋Ÿฌ ์„ค์ •
file_handler = RotatingFileHandler('logs/server.log', maxBytes=10240000, backupCount=10)
file_handler.setFormatter(logging.Formatter(
    '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
))
file_handler.setLevel(logging.INFO)

# ์ฝ˜์†” ํ•ธ๋“ค๋Ÿฌ ์„ค์ •
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
))
console_handler.setLevel(logging.INFO)

# Flask ์•ฑ ๋กœ๊ฑฐ ์„ค์ •
app.logger.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.addHandler(console_handler)

# ๋ฃจํŠธ ๋กœ๊ฑฐ ์„ค์ •
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
root_logger.addHandler(console_handler)

# Werkzeug ๋กœ๊ฑฐ ์„ค์ •
werkzeug_logger = logging.getLogger('werkzeug')
werkzeug_logger.setLevel(logging.INFO)
werkzeug_logger.handlers.clear()
werkzeug_handler = logging.StreamHandler(sys.stdout)
werkzeug_handler.setFormatter(logging.Formatter(
    '%(asctime)s - %(levelname)s - %(message)s'
))
werkzeug_logger.addHandler(werkzeug_handler)

# ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํ™•์ธ (๋””๋ฒ„๊น…์šฉ)
app.logger.info('=' * 80)
app.logger.info('ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํ™•์ธ:')
app.logger.info(f'  PORT: {port}')
app.logger.info(f'  HOST: {host}')
app.logger.info(f'  SECRET_KEY: {"์„ค์ •๋จ" if os.environ.get("SECRET_KEY") else "โš ๏ธ ์„ค์ •๋˜์ง€ ์•Š์Œ"}')
app.logger.info(f'  DATABASE_URL: {"์„ค์ •๋จ" if os.environ.get("DATABASE_URL") else "SQLite ์‚ฌ์šฉ (๊ธฐ๋ณธ๊ฐ’)"}')
app.logger.info(f'  GEMINI_API_KEY: {"์„ค์ •๋จ" if os.environ.get("GEMINI_API_KEY") else "์„ค์ •๋˜์ง€ ์•Š์Œ"}')
app.logger.info(f'  OLLAMA_BASE_URL: {os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434")}')
app.logger.info('=' * 80)

app.logger.info(f'์„œ๋ฒ„ ์‹œ์ž‘ - Host: {host}, Port: {port}')

if __name__ == '__main__':
    try:
        print(f"[{__name__}] ์„œ๋ฒ„ ์‹œ์ž‘: http://{host}:{port}")
        print(f"[{__name__}] ๋กœ๊ทธ๋Š” ์ฝ˜์†”๊ณผ logs/server.log ํŒŒ์ผ์— ๊ธฐ๋ก๋ฉ๋‹ˆ๋‹ค.")
        
        # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํ™•์ธ ์ถœ๋ ฅ
        print("=" * 80)
        print("ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํ™•์ธ:")
        print(f"  PORT: {port}")
        print(f"  HOST: {host}")
        print(f"  SECRET_KEY: {'์„ค์ •๋จ' if os.environ.get('SECRET_KEY') else 'โš ๏ธ ์„ค์ •๋˜์ง€ ์•Š์Œ'}")
        print(f"  DATABASE_URL: {'์„ค์ •๋จ' if os.environ.get('DATABASE_URL') else 'SQLite ์‚ฌ์šฉ (๊ธฐ๋ณธ๊ฐ’)'}")
        print(f"  GEMINI_API_KEY: {'์„ค์ •๋จ' if os.environ.get('GEMINI_API_KEY') else '์„ค์ •๋˜์ง€ ์•Š์Œ'}")
        print(f"  OLLAMA_BASE_URL: {os.environ.get('OLLAMA_BASE_URL', 'http://localhost:11434')}")
        print("=" * 80)
        
        app.run(host=host, port=port, debug=False, use_reloader=False)
    except Exception as e:
        print(f"์„œ๋ฒ„ ์‹œ์ž‘ ์˜ค๋ฅ˜: {e}")
        import traceback
        traceback.print_exc()
        # Hugging Face Space์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ณด์ด๋„๋ก sys.exit ์‚ฌ์šฉ
        sys.exit(1)