Spaces:
Sleeping
Sleeping
Refactor: Reduce comments in inference.py
Browse files- inference.py +2 -5
inference.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Content Moderation Inference Script
|
| 3 |
Env vars: API_BASE_URL, MODEL_NAME, HF_TOKEN, SERVER_URL, TASK_NAME
|
| 4 |
-
USE_LOCAL_MODEL=true → local transformers pipeline (Llama-3.1-8B-Instruct)
|
| 5 |
-
USE_LOCAL_MODEL=false → OpenAI-compatible HF API (default)
|
| 6 |
"""
|
| 7 |
|
| 8 |
import json
|
|
@@ -13,7 +11,6 @@ from typing import Dict, Any, List, Optional
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
import requests
|
| 15 |
|
| 16 |
-
# Load environment variables from .env file
|
| 17 |
load_dotenv()
|
| 18 |
|
| 19 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
|
@@ -41,11 +38,11 @@ Required JSON fields:
|
|
| 41 |
- "decision": one of "approve", "reject", "escalate", "flag"
|
| 42 |
- "reason": brief explanation (max 2 sentences)
|
| 43 |
- "confidence": float between 0.0 and 1.0
|
| 44 |
-
- "labels": list of applicable labels
|
| 45 |
|
| 46 |
Decision guidelines:
|
| 47 |
- approve: content is safe and legitimate
|
| 48 |
-
- reject: content clearly violates policy
|
| 49 |
- flag: content is borderline or needs human review
|
| 50 |
- escalate: uncertain, requires specialist review
|
| 51 |
|
|
|
|
| 1 |
"""
|
| 2 |
Content Moderation Inference Script
|
| 3 |
Env vars: API_BASE_URL, MODEL_NAME, HF_TOKEN, SERVER_URL, TASK_NAME
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
import json
|
|
|
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
import requests
|
| 13 |
|
|
|
|
| 14 |
load_dotenv()
|
| 15 |
|
| 16 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
|
|
|
| 38 |
- "decision": one of "approve", "reject", "escalate", "flag"
|
| 39 |
- "reason": brief explanation (max 2 sentences)
|
| 40 |
- "confidence": float between 0.0 and 1.0
|
| 41 |
+
- "labels": list of applicable labels
|
| 42 |
|
| 43 |
Decision guidelines:
|
| 44 |
- approve: content is safe and legitimate
|
| 45 |
+
- reject: content clearly violates policy
|
| 46 |
- flag: content is borderline or needs human review
|
| 47 |
- escalate: uncertain, requires specialist review
|
| 48 |
|