import gradio as gr import joblib # Define a function for the Gradio interface def predict_risk(Age, hOCP, hMisCrg, hHRT, CA125, HE4, FBS, USG): # Load the trained model model = joblib.load('RDF_OvCa_Final.joblib') # Create a DataFrame with the input data input_data = pd.DataFrame({ 'Age': [Age], 'hOCP': [hOCP], 'hMisCrg': [hMisCrg], 'hHRT': [hHRT], 'CA125': [CA125], 'HE4': [HE4], 'FBS': [FBS], 'USG': [USG] }) # Predict the probability of malignancy (class 1) probability = model.predict_proba(input_data)[:, 1][0] # Scale the risk score to -1 to +1 risk_score = 2 * probability - 1 # Determine the predicted status status = "malignant" if probability >= cutoff else "benign" result = f"The OvaCa Risk Score is {risk_score:.2f}. Based on it, the probability is more of {status} ({1 if status == 'malignant' else 0})." return result # Define the Gradio interface iface = gr.Interface( fn=predict_risk, inputs=[ gr.inputs.Number(label="Age of patient in years"), gr.inputs.Radio([0, 1], label="History of OCP intake (0: No 1: Yes)"), gr.inputs.Radio([0, 1], label="History of Miscarriage (0: No 1: Yes)"), gr.inputs.Radio([0, 1], label="History of HRT (0: No 1: Yes)"), gr.inputs.Number(label="Serum CA125 level"), gr.inputs.Number(label="Serum HE4 level"), gr.inputs.Number(label="Serum Fasting Blood Sugar Level"), gr.inputs.Radio([0, 1], label="USG Finding (0: Absent or Single Finding 1: More Than 1 Findings)") ], outputs=gr.outputs.Textbox(label="Result (Risk Score on a Scale of -1 to +1, where >0 ~ Malignant)") ) # Launch the Gradio interface iface.launch()