rangerrRed commited on
Commit
246f1ab
·
verified ·
1 Parent(s): 42a0157

Update chest_utils.py

Browse files
Files changed (1) hide show
  1. chest_utils.py +43 -4
chest_utils.py CHANGED
@@ -1,8 +1,47 @@
1
  import joblib
 
2
 
3
- model = joblib.load("chest_model.joblib")
 
4
 
5
- def predict_chest(age, cough, fever, breathing):
6
- features = [[age, cough == "Yes", fever == "Yes", breathing == "Yes"]]
7
- return model.predict(features)[0]
 
 
 
 
 
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import joblib
2
+ import numpy as np
3
 
4
+ # Load the trained chest model
5
+ chest_model = joblib.load("chest_model.joblib")
6
 
7
+ # Define clinical questions mapped to conditions
8
+ condition_questions = {
9
+ "Asthma": "Do you have shortness of breath or chest tightness?",
10
+ "Bronchiectasis": "Have you been experiencing chronic cough with sputum?",
11
+ "COPD": "Are you experiencing difficulty breathing and chronic cough?",
12
+ "Lung Cancer": "Have you noticed unexplained weight loss or coughing blood?",
13
+ "Pneumonia": "Do you have a fever, chills, and chest pain?",
14
+ "Tuberculosis": "Have you had a persistent cough for more than 3 weeks?"
15
+ }
16
 
17
+ # Helper encoding functions
18
+ def encode_gender(gender):
19
+ return 0 if gender == "Male" else 1
20
+
21
+ def encode_view_position(position):
22
+ return 0 if position == "PA" else 1
23
+
24
+ # Predict function for combined model (with image not used in model itself)
25
+ def predict_chest(image, age, gender, view_position, conditions):
26
+ """
27
+ Parameters:
28
+ - image: uploaded X-ray (optional for future model use)
29
+ - age: int
30
+ - gender: 'Male' or 'Female'
31
+ - view_position: 'PA' or 'AP'
32
+ - conditions: list of 10 binary values (0 or 1)
33
+
34
+ Returns:
35
+ - 'Chest Disease Detected' or 'No Chest Disease Detected'
36
+ """
37
+ gender_encoded = encode_gender(gender)
38
+ position_encoded = encode_view_position(view_position)
39
+
40
+ if len(conditions) != 10:
41
+ raise ValueError("Expected 10 binary values for conditions.")
42
+
43
+ # Combine all features into one row
44
+ features = np.array([[age, gender_encoded, position_encoded] + conditions])
45
+
46
+ prediction = chest_model.predict(features)[0]
47
+ return "Chest Disease Detected" if prediction == 1 else "No Chest Disease Detected"