File size: 1,538 Bytes
81f6928 |
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 |
"""
Hugging Face ํ ํฐ ๊ด๋ฆฌ ๋ชจ๋
Google Gemini API ํค ๊ด๋ฆฌ ๋ฐฉ์๊ณผ ๋์ผํ ํจํด์ผ๋ก ๊ตฌํ
"""
import os
from typing import Optional
def get_huggingface_token() -> str:
"""
Hugging Face ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ (ํ๊ฒฝ ๋ณ์ ์ฐ์ , ์์ผ๋ฉด DB์์)
Returns:
Hugging Face ํ ํฐ ๋ฌธ์์ด (์์ผ๋ฉด ๋น ๋ฌธ์์ด)
"""
# ํ๊ฒฝ ๋ณ์์์ ๋จผ์ ํ์ธ
token = os.getenv('HUGGINGFACE_HUB_TOKEN', '').strip()
if not token:
token = os.getenv('HF_TOKEN', '').strip()
if token:
print(f"[Hugging Face] ํ๊ฒฝ ๋ณ์์์ ํ ํฐ ๊ฐ์ ธ์ด (๊ธธ์ด: {len(token)}์)")
return token
# DB์์ ๊ฐ์ ธ์ค๊ธฐ (์ํ ์ฐธ์กฐ ๋ฐฉ์ง๋ฅผ ์ํด ์ฌ๊ธฐ์ ์ํฌํธ)
try:
from app.database import SystemConfig
token = SystemConfig.get_config('huggingface_token', '').strip()
if token:
print(f"[Hugging Face] DB์์ ํ ํฐ ๊ฐ์ ธ์ด (๊ธธ์ด: {len(token)}์)")
else:
print(f"[Hugging Face] DB์ ํ ํฐ์ด ์๊ฑฐ๋ ๋น์ด์์")
return token
except Exception as e:
print(f"[Hugging Face] DB์์ ํ ํฐ ์กฐํ ์คํจ: {e}")
return ''
def reset_huggingface_token():
"""
Hugging Face ํ ํฐ ์บ์ ์ด๊ธฐํ (ํ ํฐ์ด ์
๋ฐ์ดํธ๋ ํ ํธ์ถ)
"""
# ํ์ฌ๋ ๋จ์ํ ํจ์๋ฅผ ๋ค์ ํธ์ถํ๋ฉด ๋์ง๋ง,
# ํฅํ ์บ์ฑ์ด ์ถ๊ฐ๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ ํจ์
pass
|