Spaces:
Sleeping
Sleeping
Varun-L commited on
Commit ·
988d30b
1
Parent(s): 6ffe1d8
commit 2
Browse files- algo.py +0 -21
- app.py +34 -18
- hearing.csv +79 -0
- requirements.txt +4 -0
algo.py
CHANGED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
def assess_risk(age, gender, mother_education, father_education, genetical, prenatal_problem, postnatal_problem, identified_age):
|
| 3 |
-
input_data = [[age, gender, mother_education, father_education, genetical, prenatal_problem, postnatal_problem, identified_age]]
|
| 4 |
-
predicted_loss = model.predict(input_data)[0]
|
| 5 |
-
if predicted_loss >= 50:
|
| 6 |
-
return "High risk of hearing loss detected. We recommend consulting a specialist."
|
| 7 |
-
else:
|
| 8 |
-
return "Low risk of hearing loss detected. Regular check-ups are recommended."
|
| 9 |
-
|
| 10 |
-
# Example usage
|
| 11 |
-
age = 5
|
| 12 |
-
gender = 'F'
|
| 13 |
-
mother_education = 'DEGREE'
|
| 14 |
-
father_education = 'INTER'
|
| 15 |
-
genetical = 1
|
| 16 |
-
prenatal_problem = 0
|
| 17 |
-
postnatal_problem = 1
|
| 18 |
-
identified_age = 1.5
|
| 19 |
-
|
| 20 |
-
result = assess_risk(age, gender, mother_education, father_education, genetical, prenatal_problem, postnatal_problem, identified_age)
|
| 21 |
-
print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -5,40 +5,52 @@ from sklearn.model_selection import train_test_split
|
|
| 5 |
|
| 6 |
# Load the data
|
| 7 |
data = pd.read_csv('hearing.csv')
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Split the data into features and target
|
| 10 |
-
X = data.drop('
|
| 11 |
-
y = data['
|
|
|
|
| 12 |
|
| 13 |
# Split the data into training and test sets
|
| 14 |
-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2
|
| 15 |
|
| 16 |
# Train the model
|
| 17 |
-
model = Lasso()
|
| 18 |
model.fit(X_train, y_train)
|
| 19 |
|
| 20 |
-
def predict_hearing_loss(GENDER, GENETICAL, MENARIKAM, PROBLEM_PRENATAL, PROBLEM_POSTNATAL, DURING_BIRTH, SIBLINGS_PROBLEM, LEFT_EAR, RIGHT_EAR):
|
| 21 |
# Create a DataFrame from the inputs
|
| 22 |
input_data = pd.DataFrame([{
|
| 23 |
-
'GENDER': GENDER,
|
| 24 |
-
'GENETICAL': GENETICAL,
|
| 25 |
-
'MENARIKAM': MENARIKAM,
|
| 26 |
-
'PROBLEM_PRENATAL': PROBLEM_PRENATAL,
|
| 27 |
-
'PROBLEM_POSTNATAL': PROBLEM_POSTNATAL,
|
| 28 |
-
'DURING_BIRTH': DURING_BIRTH,
|
| 29 |
-
'SIBLINGS_PROBLEM': SIBLINGS_PROBLEM,
|
| 30 |
-
'
|
| 31 |
-
'
|
| 32 |
}])
|
| 33 |
-
|
| 34 |
# Make the prediction
|
| 35 |
prediction = model.predict(input_data)
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
interface = gr.Interface(
|
| 40 |
fn=predict_hearing_loss,
|
| 41 |
inputs=[
|
|
|
|
|
|
|
| 42 |
gr.Radio(['Male', 'Female'], label="GENDER"),
|
| 43 |
gr.Radio(['Yes', 'No'], label="GENETICAL"),
|
| 44 |
gr.Radio(['Yes', 'No'], label="MENARIKAM"),
|
|
@@ -49,8 +61,12 @@ interface = gr.Interface(
|
|
| 49 |
gr.Number(label="LEFT_EAR"),
|
| 50 |
gr.Number(label="RIGHT_EAR")
|
| 51 |
],
|
| 52 |
-
outputs=gr.Textbox(label="HEARING_LOSS", type="text"),
|
| 53 |
title="Hearing Health Risk Assessment Tool",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
description="Input the information to assess the risk of hearing health issues."
|
| 55 |
)
|
| 56 |
|
|
|
|
| 5 |
|
| 6 |
# Load the data
|
| 7 |
data = pd.read_csv('hearing.csv')
|
| 8 |
+
data = data.drop("AGE",axis=1)
|
| 9 |
+
data = data.dropna(axis=0)
|
| 10 |
|
| 11 |
# Split the data into features and target
|
| 12 |
+
X = data.drop('HEARING LOSS(100)/LESS', axis=1)
|
| 13 |
+
y = data['HEARING LOSS(100)/LESS']
|
| 14 |
+
|
| 15 |
|
| 16 |
# Split the data into training and test sets
|
| 17 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
|
| 18 |
|
| 19 |
# Train the model
|
| 20 |
+
model = Lasso(alpha=0.1,random_state=42)
|
| 21 |
model.fit(X_train, y_train)
|
| 22 |
|
| 23 |
+
def predict_hearing_loss(NAME,AGE,GENDER, GENETICAL, MENARIKAM, PROBLEM_PRENATAL, PROBLEM_POSTNATAL, DURING_BIRTH, SIBLINGS_PROBLEM, LEFT_EAR, RIGHT_EAR):
|
| 24 |
# Create a DataFrame from the inputs
|
| 25 |
input_data = pd.DataFrame([{
|
| 26 |
+
'GENDER': 1 if GENDER == 'Male' else 0,
|
| 27 |
+
'GENETICAL': 1 if GENETICAL == 'Yes' else 0,
|
| 28 |
+
'MENARIKAM': 1 if MENARIKAM == 'Yes' else 0,
|
| 29 |
+
'PROBLEM_PRENATAL': 1 if PROBLEM_PRENATAL == 'Yes' else 0,
|
| 30 |
+
'PROBLEM_POSTNATAL': 1 if PROBLEM_POSTNATAL == 'Yes' else 0,
|
| 31 |
+
'DURING_BIRTH': 1 if DURING_BIRTH == 'Yes' else 0,
|
| 32 |
+
'SIBLINGS_PROBLEM': 1 if SIBLINGS_PROBLEM == 'Yes' else 0,
|
| 33 |
+
'LEFT_N': LEFT_EAR,
|
| 34 |
+
'RIGHT_N': RIGHT_EAR
|
| 35 |
}])
|
|
|
|
| 36 |
# Make the prediction
|
| 37 |
prediction = model.predict(input_data)
|
| 38 |
+
|
| 39 |
+
rec = ""
|
| 40 |
+
if prediction[0] >= 77:
|
| 41 |
+
rec = "Severe hearing loss detected later. Immediate attention needed. Seek professional medical advice if not taken already and consider hearing aids or cochlear implants"
|
| 42 |
+
elif prediction[0] >=50:
|
| 43 |
+
rec = "Moderate hearing loss detected. Schedule regular hearing assessments and consider using hearing aids if necessary."
|
| 44 |
+
else:
|
| 45 |
+
rec = "Minor hearing loss detected. Keep monitoring the child's hearing and consult a doctor if there are any concerns."
|
| 46 |
+
|
| 47 |
+
return prediction[0],rec
|
| 48 |
|
| 49 |
interface = gr.Interface(
|
| 50 |
fn=predict_hearing_loss,
|
| 51 |
inputs=[
|
| 52 |
+
gr.Textbox(label="Name of the Pupil"),
|
| 53 |
+
gr.Number(label="AGE"),
|
| 54 |
gr.Radio(['Male', 'Female'], label="GENDER"),
|
| 55 |
gr.Radio(['Yes', 'No'], label="GENETICAL"),
|
| 56 |
gr.Radio(['Yes', 'No'], label="MENARIKAM"),
|
|
|
|
| 61 |
gr.Number(label="LEFT_EAR"),
|
| 62 |
gr.Number(label="RIGHT_EAR")
|
| 63 |
],
|
| 64 |
+
outputs=[gr.Textbox(label="HEARING_LOSS", type="text"),gr.Textbox(label="Recommendation", type="text")],
|
| 65 |
title="Hearing Health Risk Assessment Tool",
|
| 66 |
+
theme="gradio/monochrome",
|
| 67 |
+
allow_flagging=False,
|
| 68 |
+
css="footer {display: none !important}",
|
| 69 |
+
article=article
|
| 70 |
description="Input the information to assess the risk of hearing health issues."
|
| 71 |
)
|
| 72 |
|
hearing.csv
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AGE,HEARING LOSS(100)/LESS,GENDER,GENETICAL,MENARIKAM,PROBLEM_PRENATAL,PROBLEM_POSTNATAL,DURING_BIRTH,SIBLINGS_PROBLEM,LEFT_N,RIGHT_N
|
| 2 |
+
4,90,0,0,0,0,1,0,1,90,90
|
| 3 |
+
5,75,0,1,1,0,0,0,1,70,75
|
| 4 |
+
5,100,0,0,0,0,0,0,0,100,100
|
| 5 |
+
7,,1,0,0,1,0,0,1,102,100
|
| 6 |
+
7,89,1,1,1,0,1,1,1,90,89
|
| 7 |
+
7,98,0,1,1,0,0,0,1,98,98
|
| 8 |
+
4,100,1,1,1,0,0,0,1,100,100
|
| 9 |
+
8,60,0,0,0,0,0,0,1,60,70
|
| 10 |
+
6,45,1,0,0,0,0,0,1,45,45
|
| 11 |
+
4,90,0,1,1,0,0,1,1,90,90
|
| 12 |
+
5,85,1,0,1,0,0,1,1,85,70
|
| 13 |
+
6,90,0,0,0,1,1,1,1,90,85
|
| 14 |
+
8,95,1,0,0,1,1,1,1,90,85
|
| 15 |
+
5,68,0,1,1,0,0,1,0,68,68
|
| 16 |
+
5,100,1,0,0,0,1,1,1,100,100
|
| 17 |
+
6,100,0,0,0,0,0,1,0,100,100
|
| 18 |
+
5,100,1,1,1,0,0,1,0,100,100
|
| 19 |
+
4,90,1,0,0,0,0,0,0,90,90
|
| 20 |
+
3.5,90,1,1,1,0,0,1,0,90,90
|
| 21 |
+
4,90,0,0,0,1,0,1,0,90,90
|
| 22 |
+
3,100,1,1,1,0,0,1,0,100,100
|
| 23 |
+
4,100,1,0,0,0,0,1,0,100,100
|
| 24 |
+
5,100,0,0,0,0,0,1,0,100,100
|
| 25 |
+
5,100,1,0,0,1,1,1,0,70,100
|
| 26 |
+
5,80,0,0,0,0,0,1,1,80,75
|
| 27 |
+
15,100,0,0,0,0,1,1,1,90,100
|
| 28 |
+
3,,1,1,1,0,0,0,0,90,80
|
| 29 |
+
3.5,,1,1,1,0,0,0,1,90,78
|
| 30 |
+
4,,1,1,1,0,0,0,1,87,93
|
| 31 |
+
6,84,1,1,1,0,0,0,1,87,93
|
| 32 |
+
5,,1,0,0,0,0,0,0,90,90
|
| 33 |
+
5,70,1,0,0,0,0,0,0,70,70
|
| 34 |
+
8,,1,0,0,0,0,0,0,76,96
|
| 35 |
+
3.5,90,1,1,1,0,0,0,0,70,90
|
| 36 |
+
7,,0,1,1,0,0,0,1,70,80
|
| 37 |
+
4,,0,0,0,0,0,0,0,100,90
|
| 38 |
+
3,90,1,0,0,0,0,1,0,90,90
|
| 39 |
+
3.5,100,1,0,0,0,1,1,0,100,100
|
| 40 |
+
2.5,90,1,1,1,1,1,0,0,90,90
|
| 41 |
+
4,95,1,0,0,0,1,1,0,100,90
|
| 42 |
+
6,100,1,1,1,1,1,1,0,97,65
|
| 43 |
+
4.5,80,1,1,1,0,0,0,0,85,75
|
| 44 |
+
5,100,1,1,1,0,0,0,0,100,100
|
| 45 |
+
6,90,0,1,1,0,0,0,0,50,95
|
| 46 |
+
5,90,1,0,0,0,0,0,0,90,90
|
| 47 |
+
4,100,0,1,1,0,0,0,0,100,100
|
| 48 |
+
4.5,100,1,0,0,0,0,0,0,100,100
|
| 49 |
+
5,100,1,0,0,0,0,1,0,90,100
|
| 50 |
+
4,60,0,0,0,0,0,0,0,60,60
|
| 51 |
+
6.5,100,1,1,1,0,0,1,1,100,100
|
| 52 |
+
3,100,0,1,1,0,0,1,1,100,100
|
| 53 |
+
7,75,0,1,1,0,0,1,0,45,20
|
| 54 |
+
6,100,1,0,0,0,0,1,0,99,100
|
| 55 |
+
5,90,1,0,0,0,0,0,0,90,90
|
| 56 |
+
4,90,1,1,1,0,0,1,0,90,90
|
| 57 |
+
6,75,1,1,1,1,1,1,0,70,75
|
| 58 |
+
6,100,1,1,1,1,1,1,1,100,100
|
| 59 |
+
6,100,0,0,0,0,0,1,0,100,100
|
| 60 |
+
5,90,0,1,1,0,0,1,0,95,95
|
| 61 |
+
3.5,110,0,1,1,0,0,1,0,110,110
|
| 62 |
+
7,90,0,0,0,0,0,1,0,93,98
|
| 63 |
+
6,60,0,0,0,1,0,1,0,60,40
|
| 64 |
+
3.5,90,1,1,1,1,1,0,0,90,90
|
| 65 |
+
5,68,1,0,0,0,0,0,0,70,70
|
| 66 |
+
4,50,1,1,1,1,1,0,0,50,50
|
| 67 |
+
6,75,1,1,1,0,0,1,0,80,90
|
| 68 |
+
8,80,1,0,0,1,1,1,0,85,75
|
| 69 |
+
3.5,80,1,0,0,0,0,0,0,80,80
|
| 70 |
+
3,75,0,0,0,0,0,1,0,75,75
|
| 71 |
+
7,90,0,0,0,0,0,1,0,90,90
|
| 72 |
+
5,90,1,0,0,0,0,0,0,83,90
|
| 73 |
+
6,80,1,1,1,0,0,1,0,80,100
|
| 74 |
+
7.5,90,1,1,1,0,0,0,0,85,95
|
| 75 |
+
5,100,1,0,0,1,1,1,0,100,100
|
| 76 |
+
6,90,1,0,0,0,1,1,0,90,90
|
| 77 |
+
5,90,1,1,1,0,0,1,0,90,90
|
| 78 |
+
5,90,0,0,0,0,0,1,0,90,90
|
| 79 |
+
6,100,0,1,1,0,0,1,0,100,100
|
requirements.txt
CHANGED
|
@@ -27,6 +27,7 @@ huggingface-hub==0.23.3
|
|
| 27 |
idna==3.7
|
| 28 |
importlib_resources==6.4.0
|
| 29 |
Jinja2==3.1.4
|
|
|
|
| 30 |
jsonschema==4.22.0
|
| 31 |
jsonschema-specifications==2023.12.1
|
| 32 |
kiwisolver==1.4.5
|
|
@@ -54,11 +55,14 @@ requests==2.32.3
|
|
| 54 |
rich==13.7.1
|
| 55 |
rpds-py==0.18.1
|
| 56 |
ruff==0.4.8
|
|
|
|
|
|
|
| 57 |
semantic-version==2.10.0
|
| 58 |
shellingham==1.5.4
|
| 59 |
six==1.16.0
|
| 60 |
sniffio==1.3.1
|
| 61 |
starlette==0.37.2
|
|
|
|
| 62 |
tomlkit==0.12.0
|
| 63 |
toolz==0.12.1
|
| 64 |
tqdm==4.66.4
|
|
|
|
| 27 |
idna==3.7
|
| 28 |
importlib_resources==6.4.0
|
| 29 |
Jinja2==3.1.4
|
| 30 |
+
joblib==1.4.2
|
| 31 |
jsonschema==4.22.0
|
| 32 |
jsonschema-specifications==2023.12.1
|
| 33 |
kiwisolver==1.4.5
|
|
|
|
| 55 |
rich==13.7.1
|
| 56 |
rpds-py==0.18.1
|
| 57 |
ruff==0.4.8
|
| 58 |
+
scikit-learn==1.5.0
|
| 59 |
+
scipy==1.13.1
|
| 60 |
semantic-version==2.10.0
|
| 61 |
shellingham==1.5.4
|
| 62 |
six==1.16.0
|
| 63 |
sniffio==1.3.1
|
| 64 |
starlette==0.37.2
|
| 65 |
+
threadpoolctl==3.5.0
|
| 66 |
tomlkit==0.12.0
|
| 67 |
toolz==0.12.1
|
| 68 |
tqdm==4.66.4
|