Varun-L
Update 6
6769d39
import gradio as gr
import pandas as pd
from sklearn.linear_model import Lasso
from sklearn.model_selection import train_test_split
from algo import description, article
# Load the data
data = pd.read_csv('hearing.csv')
data = data.drop("AGE",axis=1)
data = data.dropna(axis=0)
# Split the data into features and target
X = data.drop('HEARING LOSS(100)/LESS', axis=1)
y = data['HEARING LOSS(100)/LESS']
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Train the model
model = Lasso(alpha=0.1,random_state=42)
model.fit(X_train, y_train)
def predict_hearing_loss(NAME,AGE,GENDER, ES, GENETICAL, MENARIKAM, PROBLEM_PRENATAL, PROBLEM_POSTNATAL, DURING_BIRTH, SIBLINGS_PROBLEM, LEFT_EAR, RIGHT_EAR):
# Create a DataFrame from the inputs
input_data = pd.DataFrame([{
'GENDER': 1 if GENDER == 'Male' else 0,
'GENETICAL': 1 if GENETICAL == 'Yes' else 0,
'MENARIKAM': 1 if MENARIKAM == 'Yes' else 0,
'PROBLEM_PRENATAL': 1 if PROBLEM_PRENATAL == 'Yes' else 0,
'PROBLEM_POSTNATAL': 1 if PROBLEM_POSTNATAL == 'Yes' else 0,
'DURING_BIRTH': 1 if DURING_BIRTH == 'Yes' else 0,
'SIBLINGS_PROBLEM': 1 if SIBLINGS_PROBLEM == 'Yes' else 0,
'LEFT_N': LEFT_EAR,
'RIGHT_N': RIGHT_EAR
}])
# Make the prediction
prediction = model.predict(input_data)
rec = ""
if prediction[0] >= 77:
rec = "Severe hearing loss detected later. Immediate attention needed. Seek professional medical advice if not taken already and consider hearing aids or cochlear implants"
elif prediction[0] >=50:
rec = "Moderate hearing loss detected. Schedule regular hearing assessments and consider using hearing aids if necessary."
else:
rec = "Minor hearing loss detected. Keep monitoring the child's hearing and consult a doctor if there are any concerns."
return round(prediction[0],2),rec
interface = gr.Interface(
fn=predict_hearing_loss,
# inputs=[
# gr.Textbox(label="Patient Id"),
# gr.Number(label="AGE"),
# gr.Radio(['Male', 'Female'], label="GENDER"),
# gr.Radio(['Yes', 'No'], label="GENETICAL"),
# gr.Radio(['Yes', 'No'], label="Consanguineous Marriages"),
# gr.Radio(['Yes', 'No'], label="PRENATAL PROBLEM "),
# gr.Radio(['Yes', 'No'], label="POSTNATAL PROBLEM"),
# gr.Radio(['Yes', 'No'], label="DURING BIRTH"),
# gr.Radio(['Yes', 'No'], label="SIBLINGS PROBLEM"),
# gr.Number(label="LEFT EAR"),
# gr.Number(label="RIGHT EAR")
# ],
inputs=[
gr.Textbox(label="Child Identification number"),
gr.Number(label="Age"),
gr.Radio(['Male', 'Female'], label="Gender"),
gr.Radio(['Poor', 'BPL', 'Middle Class', 'Upper Class'], label="Economic Status"),
gr.Radio(['Yes', 'No'], label="Any Known Genetic Hearing Loss in Family?"),
gr.Radio(['Yes', 'No'], label="Is the parent marriage a Consanguineous Marriage?"),
gr.Radio(['Yes', 'No'], label="Any Prenatal Problems?"),
gr.Radio(['Yes', 'No'], label="Any Postnatal Problems?"),
gr.Radio(['Yes', 'No'], label="Any Complications During Birth?"),
gr.Radio(['Yes', 'No'], label="Any Siblings with Hearing Problems?"),
gr.Number(label="Left Ear Hearing Loss Severity (in dB)"),
gr.Number(label="Right Ear Hearing Loss Severity (in dB)")
],
outputs=[gr.Textbox(label="HEARING LOSS %", type="text"),gr.Textbox(label="Recommendation", type="text")],
title="A Predictive Model to Find Hearing Loss in Children Using Machine Learning Algorithms",
theme="gradio/monochrome",
allow_flagging=False,
css="footer {display: none !important}",
article=article,
description=description
)
interface.launch()