Spaces:
Sleeping
Sleeping
Download inference_api.py from mandar1007/cs1-team20: direct link, hf CLI and curl.
- Browser
- Download file 463 Bytes
-
https://huggingface.co/spaces/mandar1007/cs1-team20/resolve/main/inference_api.py
- Command line
-
hf download hf://spaces/mandar1007/cs1-team20/inference_api.py
-
curl -L -o inference_api.py https://huggingface.co/spaces/mandar1007/cs1-team20/resolve/main/inference_api.py
463 Bytes
| 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)} | |