|
|
""" |
|
|
Hugging Face Spacesμ© Flask μ ν리μΌμ΄μ
μ§μ
μ |
|
|
""" |
|
|
import sys |
|
|
import os |
|
|
import logging |
|
|
from logging.handlers import RotatingFileHandler |
|
|
|
|
|
|
|
|
if sys.platform == 'win32': |
|
|
sys.stdout.reconfigure(encoding='utf-8') |
|
|
sys.stderr.reconfigure(encoding='utf-8') |
|
|
|
|
|
from app import create_app |
|
|
|
|
|
app = create_app() |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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_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 "β οΈ μ€μ λμ§ μμ"}') |
|
|
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 'β οΈ μ€μ λμ§ μμ'}") |
|
|
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() |
|
|
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|