File size: 463 Bytes
ce60622
 
 
f195fcb
 
 
 
 
04a81d2
ce60622
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
from huggingface_hub import InferenceClient

# Pin the full model repo ID (owner/name)
MODEL_ID = os.getenv(
    "HF_API_MODEL_ID",
    "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
)
HF_TOKEN = os.getenv("runtime_inference")

_client = InferenceClient(model=MODEL_ID, token=HF_TOKEN)

def run_inference_api(text: str):
    try:
        return _client.text_classification(text)
    except Exception as e:
        return {"error": str(e)}