| from __future__ import annotations | |
| import json | |
| import os | |
| import requests | |
| MODEL_REPO = "arun-gharami/lead-ai-customer-predictor" | |
| HF_TOKEN = os.environ.get("HF_TOKEN", "") | |
| def call_hf_inference_api(payload: dict) -> dict: | |
| api_url = f"https://api-inference.huggingface.co/models/{MODEL_REPO}" | |
| headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {} | |
| response = requests.post(api_url, headers=headers, json={"inputs": payload}, timeout=30) | |
| response.raise_for_status() | |
| return response.json() | |
| if __name__ == "__main__": | |
| sample_payload = { | |
| "customer_tenure": 11, | |
| "total_spent": 900, | |
| "last_purchase_days": 17, | |
| "visit_count": 26, | |
| "email_open_rate": 0.62, | |
| "discount_usage": 0.22, | |
| "support_tickets": 1, | |
| "satisfaction_score": 8.4, | |
| } | |
| print("Payload:") | |
| print(json.dumps(sample_payload, indent=2)) | |
| print("\nResponse:") | |
| try: | |
| print(json.dumps(call_hf_inference_api(sample_payload), indent=2)) | |
| except Exception as exc: | |
| print(f"API call failed: {exc}") | |
| print("Run local scoring by importing predict_customer_status from app.py.") | |