File size: 1,151 Bytes
61b4ff5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
6์ฃผ์ฐจ ๋ชจ๋ธ ์„ค์ • โ€” HuggingFace Inference API
===========================================
ํ† ํฐ์€ .env ์˜ HF_TOKEN ๋˜๋Š” HUGGINGFACEHUB_API_TOKEN ์—์„œ ์ฝ๋Š”๋‹ค.
HF Space์— ๋ฐฐํฌํ•  ๋•Œ๋Š” Settings > Secrets ์— HF_TOKEN ์„ ๋“ฑ๋กํ•œ๋‹ค.
"""

from __future__ import annotations

import os

from huggingface_hub import InferenceClient

# ์Œ์‹ ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜ (ViT, food-101 ํŒŒ์ธํŠœ๋‹)
VISION_MODEL = "nateraw/food"

# ์นผ๋กœ๋ฆฌ/์˜์–‘์†Œ ์ถ”์ •์šฉ ํ…์ŠคํŠธ LLM
LLM_MODEL = "meta-llama/Meta-Llama-3-8B-Instruct"


def get_token() -> str:
    token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
    if not token:
        raise SystemExit(
            "HF_TOKEN(๋˜๋Š” HUGGINGFACEHUB_API_TOKEN) ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค.\n"
            "  1) https://huggingface.co/settings/tokens ์—์„œ Read ํ† ํฐ ๋ฐœ๊ธ‰\n"
            "  2) .env ์— HF_TOKEN=hf_xxx ์ถ”๊ฐ€ (๋กœ์ปฌ)\n"
            "  3) HF Space: Settings > Secrets ์— HF_TOKEN ๋“ฑ๋ก"
        )
    return token


def get_client() -> InferenceClient:
    """์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜์šฉ ํด๋ผ์ด์–ธํŠธ."""
    return InferenceClient(token=get_token())