Spaces:
Sleeping
Sleeping
File size: 3,851 Bytes
6ffe1d8 a52eb71 6ffe1d8 988d30b 6ffe1d8 988d30b 6ffe1d8 988d30b 6ffe1d8 988d30b 6ffe1d8 7b3cca0 6ffe1d8 988d30b 6ffe1d8 988d30b 7b3cca0 6ffe1d8 ebc00c3 6ffe1d8 ebc00c3 7b3cca0 6769d39 7b3cca0 6769d39 ebc00c3 6ffe1d8 7b3cca0 988d30b a52eb71 6ffe1d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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()
|