75 lines
2.9 KiB
Python
Raw Permalink Normal View History

2025-02-05 19:26:33 +00:00
import logging
import requests
2025-02-05 17:51:05 +00:00
2025-02-05 19:26:33 +00:00
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
)
logger = logging.getLogger(__name__)
2025-02-05 17:51:05 +00:00
2025-02-05 19:26:33 +00:00
url = "http://centurion-h2o-server.default.svc.cluster.local:8000/scoring"
# url = "http://localhost:8000/scoring"
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
def __main__(score_results:float, AT34B:int, AT12S:int, revolving_amount_percent_available_credit:float, AT28A:int, record_counts_total_trade_count:int, record_counts_negative_trade_count:int, record_counts_revolving_trade_count:int, AT33A:int, AT35A:int,
record_counts_total_inquiry_count:int, IN20S:int, RE102S:int, installment_amount_monthly_payment:float, S061S:int,
record_counts_installment_trade_count:int, BR02S:int, AGG103:float, ALL231:float, G069S:int, AT24S:int, BI02S:int)->dict:
input_data = {
"score_results": score_results,
"AT34B": AT34B,
"AT12S": AT12S,
"revolving_amount_percent_available_credit": revolving_amount_percent_available_credit,
"AT28A": AT28A,
"record_counts_total_trade_count": record_counts_total_trade_count,
"record_counts_negative_trade_count": record_counts_negative_trade_count,
"record_counts_revolving_trade_count": record_counts_revolving_trade_count,
"AT33A": AT33A,
"AT35A": AT35A,
"record_counts_total_inquiry_count": record_counts_total_inquiry_count,
"IN20S": IN20S,
"RE102S": RE102S,
"installment_amount_monthly_payment": installment_amount_monthly_payment,
"S061S": S061S,
"record_counts_installment_trade_count": record_counts_installment_trade_count,
"BR02S": BR02S,
"AGG103": AGG103,
"ALL231": ALL231,
"G069S": G069S,
"AT24S": AT24S,
"BI02S": BI02S
}
filtered_data = {key: value for key, value in input_data.items() if value is not None}
data = {
"model_name": "repeat_v1",
"features": filtered_data
}
try:
try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status() # Raise an error for HTTP issues
# Parse the response and return the "" value
response_data = response.json()
_value = response_data.get("prediction", {}).get("p1")
except requests.RequestException as error:
logger.error(f"Error while predicting: {error}")
return None
if _value is not None:
logger.info(f"Prediction : {_value}")
return {'probability': float(_value)}
else:
logger.error("Response does not contain ''")
return None
except Exception as error:
logger.error(f"Error while predicting: {error}")
return {'error': str(error)}
# finally:
# h2o.cluster().shutdown()