XSCP / app.py
DocSrvNyk's picture
Update app.py
8f074c6
import gradio as gr
from joblib import load
import numpy as np
# Load the trained XGBoost model
model = load('Model_SCD_XGB.joblib')
def predict_sickle_cell_crisis(Hct, Lymper, Age, JtPainFreq_yr):
# Prepare the input data as a numpy array
input_data = np.array([[Hct, Lymper, Age, JtPainFreq_yr]])
# Use the model to make a prediction
prediction = model.predict(input_data)[0]
prediction_prob = model.predict_proba(input_data)[0]
# Calculate the scaled risk score
risk_score = 2 * prediction_prob[1] - 1
# Prepare the result string
result_str = f"The XSCP (XGBoost Sickle-Cell Crisis Prediction) Model predicts the chances of patient going into Sickle Cell Crisis as {'Positive' if prediction == 1 else 'Negative'}, with a scaled probability Risk Score of : {risk_score:.2f}. This trained model has a F1 Accuracy of 1.00 with a 100% Precision and Recall."
return result_str
# Create Gradio Interface
iface = gr.Interface(
fn=predict_sickle_cell_crisis,
inputs=[
gr.inputs.Number(label="Hematocrit value in %"),
gr.inputs.Number(label="Lymphocyte % of TLC"),
gr.inputs.Slider(minimum=0, maximum=120, default=25, label="Age (in years)"), # Slider for Age
# gr.inputs.Number(label="Hb Haemoglobin in g/dL"),
gr.inputs.Number(label="Joint Pain Frequency as Counts in past one year"),
# gr.inputs.Radio([0, 1], label="Any H/O Joint Pain & Swelling in the past one year (1 - Yes, 0 - No)")
],
outputs=gr.outputs.Textbox()
)
iface.launch()