Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Load the model
|
6 |
+
model_filename = 'gbdt_inv_cd_ratio.joblib'
|
7 |
+
gbdt = joblib.load(model_filename)
|
8 |
+
|
9 |
+
# Define the prediction function
|
10 |
+
def predict_immune_risk(ca, mg, zn, phos):
|
11 |
+
# Prepare input data
|
12 |
+
input_data = np.array([[ca, mg, zn, phos]])
|
13 |
+
|
14 |
+
# Make predictions
|
15 |
+
predicted_class = gbdt.predict(input_data)[0]
|
16 |
+
predicted_probabilities = gbdt.predict_proba(input_data)[0]
|
17 |
+
|
18 |
+
# Determine the risk label and probability
|
19 |
+
if predicted_class == 1 or predicted_probabilities[1] > 0.5:
|
20 |
+
risk_label = "High Immune Risk (Inverted CD4/CD8 Ratio)"
|
21 |
+
probability = predicted_probabilities[1] * 100
|
22 |
+
else:
|
23 |
+
risk_label = "Low Immune Risk (Normal CD4/CD8 Ratio)"
|
24 |
+
probability = (1 - predicted_probabilities[1]) * 100 # Using the probability of the other class
|
25 |
+
|
26 |
+
return risk_label, f"{probability:.2f}%"
|
27 |
+
|
28 |
+
# Create Gradio interface
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=predict_immune_risk,
|
31 |
+
inputs=[gr.Number(label="Calcium (mg/dL)"),
|
32 |
+
gr.Number(label="Magnesium (mg/dL)"),
|
33 |
+
gr.Number(label="Zinc (mg/dL)"),
|
34 |
+
gr.Number(label="Phosphate (mg/dL)")],
|
35 |
+
outputs=[gr.Textbox(label="Immune Risk Prediction"),
|
36 |
+
gr.Textbox(label="Predicted Probability")],
|
37 |
+
title="HIV Immune Risk Predictor - CD4/CD8 Ratio and Essential Mineral Status",
|
38 |
+
description="Enter the levels of Calcium, Magnesium, Zinc, and Phosphate to predict immune risk based on Inversion of CD4/CD8 ratio."
|
39 |
+
)
|
40 |
+
|
41 |
+
# Launch the interface
|
42 |
+
iface.launch()
|