LINE-ROBOT / config.py
cwadayi's picture
Update config.py
36527a2 verified
raw
history blame
1.65 kB
# config.py
import os
import tempfile
from datetime import datetime
# --- 環境設定 ---
# 設定 Matplotlib 與 Hugging Face 模型的快取目錄
os.environ.setdefault("MPLCONFIGDIR", "/tmp/matplotlib")
os.environ.setdefault("TRANSFORMERS_CACHE", "/tmp/huggingface")
# [FIX] Assign the environment variable's value to a Python variable to make it importable.
TRANSFORMERS_CACHE = os.environ["TRANSFORMERS_CACHE"]
os.makedirs(TRANSFORMERS_CACHE, exist_ok=True)
# --- LINE Bot 憑證 ---
CHANNEL_ACCESS_TOKEN = os.getenv("CHANNEL_ACCESS_TOKEN")
CHANNEL_SECRET = os.getenv("CHANNEL_SECRET")
# --- Hugging Face Space URL ---
HF_SPACE_URL = os.getenv("SPACEURL")
if not HF_SPACE_URL:
sid = os.getenv("SPACE_ID")
if sid and "/" in sid:
author, name = sid.split("/", 1)
HF_SPACE_URL = f"https://{author.replace('_', '-')}-{name.replace('_', '-')}.hf.space"
else:
HF_SPACE_URL = ""
# --- 靜態檔案目錄 ---
STATIC_DIR = os.getenv("STATIC_DIR", os.path.join(tempfile.gettempdir(), "static"))
os.makedirs(STATIC_DIR, exist_ok=True)
# --- API 端點 ---
CWA_ALARM_API = "https://app-2.cwa.gov.tw/api/v1/earthquake/alarm/list"
USGS_API_BASE_URL = "https://earthquake.usgs.gov/fdsnws/event/1/query"
# --- AI 模型設定 ---
LLM_DEVICE = os.getenv("LLM_DEVICE")
LLM_THREADS = os.getenv("LLM_THREADS", "1")
LLM_MODEL = os.getenv("LLM_MODEL", "ckiplab/gpt2-base-chinese")
LLM_MAX_NEW_TOKENS = int(os.getenv("LLM_MAX_NEW_TOKENS", "120"))
LLM_TOP_K = int(os.getenv("LLM_TOP_K", "50"))
LLM_TEMPERATURE = float(os.getenv("LLM_TEMPERATURE", "0.7"))
# --- 顯示用當年年份 ---
CURRENT_YEAR = datetime.now().year