Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,17 +30,16 @@ def get_murmur_from_recordings(audio):
|
|
| 30 |
|
| 31 |
|
| 32 |
def get_patient_outcome(age, sex, height, weight, is_pregnant, murmur):
|
| 33 |
-
|
| 34 |
model = joblib.load("patient_outcome_classifier_v3.joblib")
|
|
|
|
|
|
|
| 35 |
is_pregnant = 1 if is_pregnant else 0
|
| 36 |
sex2int = {'Male': 0, 'Female': 1}
|
| 37 |
sex = sex2int[sex]
|
| 38 |
-
|
| 39 |
age2int = {'Neonate': 0, 'Infant': 1, 'Child': 2, 'Adolescent': 3}
|
| 40 |
age = age2int[age]
|
| 41 |
-
|
| 42 |
murmur = 0 if murmur == 'Absent' else (1 if murmur == 'Present' else 2)
|
| 43 |
-
|
| 44 |
data = pd.DataFrame({
|
| 45 |
'Age': float(age),
|
| 46 |
'Sex': float(sex),
|
|
@@ -50,14 +49,20 @@ def get_patient_outcome(age, sex, height, weight, is_pregnant, murmur):
|
|
| 50 |
'Murmur': float(murmur),
|
| 51 |
}, index=[0])
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
'
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
def predict(audio, age, sex, height, weight, is_pregnant):
|
|
@@ -88,7 +93,10 @@ demo = gr.Interface(
|
|
| 88 |
gr.Number(label="Weight", value="38.1"),
|
| 89 |
gr.Checkbox(label="Pregnant", value=False)
|
| 90 |
],
|
| 91 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 92 |
cache_examples=True,
|
| 93 |
examples=[
|
| 94 |
abnormal,
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
def get_patient_outcome(age, sex, height, weight, is_pregnant, murmur):
|
| 33 |
+
keras_model = keras.models.load_model('patient_outcome_classifier_v2.keras')
|
| 34 |
model = joblib.load("patient_outcome_classifier_v3.joblib")
|
| 35 |
+
|
| 36 |
+
# Data prep
|
| 37 |
is_pregnant = 1 if is_pregnant else 0
|
| 38 |
sex2int = {'Male': 0, 'Female': 1}
|
| 39 |
sex = sex2int[sex]
|
|
|
|
| 40 |
age2int = {'Neonate': 0, 'Infant': 1, 'Child': 2, 'Adolescent': 3}
|
| 41 |
age = age2int[age]
|
|
|
|
| 42 |
murmur = 0 if murmur == 'Absent' else (1 if murmur == 'Present' else 2)
|
|
|
|
| 43 |
data = pd.DataFrame({
|
| 44 |
'Age': float(age),
|
| 45 |
'Sex': float(sex),
|
|
|
|
| 49 |
'Murmur': float(murmur),
|
| 50 |
}, index=[0])
|
| 51 |
|
| 52 |
+
# Predict Keras
|
| 53 |
+
output = keras_model.predict(data)[0]
|
| 54 |
+
# 0 - Normal, 1 - Abnormal -> %
|
| 55 |
+
results_keras = {
|
| 56 |
+
'Normal': output[0],
|
| 57 |
+
'Abnormal': output[1]
|
| 58 |
}
|
| 59 |
|
| 60 |
+
# Predict SVC
|
| 61 |
+
output = model.predict(data)[0]
|
| 62 |
+
# 0 - Normal or 1 - Abnormal
|
| 63 |
+
results_svc = 'Normal' if x == 0 else 'Abnormal'
|
| 64 |
+
|
| 65 |
+
return results_keras, results_svc
|
| 66 |
|
| 67 |
|
| 68 |
def predict(audio, age, sex, height, weight, is_pregnant):
|
|
|
|
| 93 |
gr.Number(label="Weight", value="38.1"),
|
| 94 |
gr.Checkbox(label="Pregnant", value=False)
|
| 95 |
],
|
| 96 |
+
outputs=[
|
| 97 |
+
gr.Label(label="keras_pred"),
|
| 98 |
+
gr.Label(label="svc_pred"),
|
| 99 |
+
],
|
| 100 |
cache_examples=True,
|
| 101 |
examples=[
|
| 102 |
abnormal,
|