Zemedkun commited on
Commit
248ac16
1 Parent(s): ffca332

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -64
app.py CHANGED
@@ -53,69 +53,32 @@ def preprocess_clinical_data(age, height, weight, reported_cough_dur, heart_rate
53
  def main():
54
  st.title('TB Cough Sound Analysis')
55
 
56
- # Initialize state variables
57
- page = st.session_state.get('page', 0)
58
- st.session_state['page'] = page
59
 
60
- # Create multi-step form
61
- if page == 0:
62
- st.write('**Step 1: Upload Cough Sound Recording**')
63
- audio_file = st.file_uploader("Upload a cough sound recording", type=['wav', 'mp3'])
64
- if audio_file is not None:
65
- st.audio(audio_file)
66
- st.session_state['audio_file'] = audio_file
67
- if st.button('Next'):
68
- st.session_state['page'] = 1
69
 
70
- elif page == 1:
71
  st.write('**Step 2: Enter Clinical Data**')
72
- age = st.number_input('Age', min_value=0, step=1, format='%d')
73
- height = st.number_input('Height (in cm)', min_value=0.0, step=0.1, format='%f')
74
- weight = st.number_input('Weight (in kg)', min_value=0.0, step=0.1, format='%f')
75
- reported_cough_dur = st.number_input('Reported Cough Duration (in days)', min_value=0, step=1, format='%d')
76
- heart_rate = st.number_input('Heart Rate (beats per minute)', min_value=0, step=1, format='%d')
77
- temperature = st.number_input('Body Temperature (in °C)', min_value=0.0, step=0.1, format='%f')
78
  sex = st.radio('Sex', ['Male', 'Female'])
79
- tb_prior = st.selectbox('TB Prior', ['No', 'Not sure', 'Yes'])
80
- tb_prior_Pul = st.selectbox('TB Prior - Pulmonary', ['No', 'Yes'])
81
- tb_prior_Extrapul = st.selectbox('TB Prior - Extrapulmonary', ['No', 'Yes'])
82
- tb_prior_Unknown = st.selectbox('TB Prior - Unknown', ['No', 'Yes'])
83
- hemoptysis = st.selectbox('Hemoptysis', ['No', 'Yes'])
84
- weight_loss = st.selectbox('Weight Loss', ['No', 'Yes'])
85
- smoke_lweek = st.selectbox('Smoking Last Week', ['No', 'Yes'])
86
- fever = st.selectbox('Fever', ['No', 'Yes'])
87
- night_sweats = st.selectbox('Night Sweats', ['No', 'Yes'])
88
-
89
- if st.button('Next'):
90
- st.session_state['page'] = 2
91
-
92
- elif page == 2:
93
- st.write('**Step 3: Review Input Data**')
94
- st.write('**Clinical Data:**')
95
- st.write(f"- Age: {age}")
96
- st.write(f"- Height: {height} cm")
97
- st.write(f"- Weight: {weight} kg")
98
- st.write(f"- Reported Cough Duration: {reported_cough_dur} days")
99
- st.write(f"- Heart Rate: {heart_rate} bpm")
100
- st.write(f"- Temperature: {temperature} °C")
101
- st.write(f"- Sex: {sex}")
102
- st.write(f"- TB Prior: {tb_prior}")
103
- st.write(f"- TB Prior - Pulmonary: {tb_prior_Pul}")
104
- st.write(f"- TB Prior - Extrapulmonary: {tb_prior_Extrapul}")
105
- st.write(f"- TB Prior - Unknown: {tb_prior_Unknown}")
106
- st.write(f"- Hemoptysis: {hemoptysis}")
107
- st.write(f"- Weight Loss: {weight_loss}")
108
- st.write(f"- Smoking Last Week: {smoke_lweek}")
109
- st.write(f"- Fever: {fever}")
110
- st.write(f"- Night Sweats: {night_sweats}")
111
-
112
- if st.button('Next'):
113
- st.session_state['page'] = 3
114
-
115
- elif page == 3:
116
- st.write('**Step 4: Prediction**')
117
- if 'audio_file' in st.session_state:
118
- audio_data = preprocess_audio(st.session_state['audio_file'])
119
  clinical_data = preprocess_clinical_data(age, height, weight, reported_cough_dur, heart_rate, temperature,
120
  sex, tb_prior, tb_prior_Pul, tb_prior_Extrapul, tb_prior_Unknown, hemoptysis, weight_loss, smoke_lweek, fever,
121
  night_sweats)
@@ -136,11 +99,6 @@ def main():
136
  st.write('**Prediction:**')
137
  st.write(f"{prediction_text}")
138
  st.write(f"{probability_label}: {result}")
139
- else:
140
- st.error('Please upload an audio file.')
141
-
142
- if st.button('Previous'):
143
- st.session_state['page'] = 2
144
 
145
  if __name__ == '__main__':
146
  main()
 
53
  def main():
54
  st.title('TB Cough Sound Analysis')
55
 
56
+ st.write('**Step 1: Upload Cough Sound Recording**')
57
+ audio_file = st.file_uploader("Upload a cough sound recording", type=['wav', 'mp3'])
 
58
 
59
+ if audio_file is not None:
60
+ st.audio(audio_file)
 
 
 
 
 
 
 
61
 
 
62
  st.write('**Step 2: Enter Clinical Data**')
63
+ age = st.slider('Age', min_value=0, max_value=100, value=30, step=1)
64
+ height = st.slider('Height (in cm)', min_value=0.0, max_value=300.0, value=170.0, step=0.1)
65
+ weight = st.slider('Weight (in kg)', min_value=0.0, max_value=200.0, value=70.0, step=0.1)
66
+ reported_cough_dur = st.slider('Reported Cough Duration (in days)', min_value=0, max_value=100, value=10, step=1)
67
+ heart_rate = st.slider('Heart Rate (beats per minute)', min_value=0, max_value=200, value=80, step=1)
68
+ temperature = st.slider('Body Temperature (in °C)', min_value=0.0, max_value=40.0, value=37.0, step=0.1)
69
  sex = st.radio('Sex', ['Male', 'Female'])
70
+ tb_prior = st.selectbox('TB Prior', ['No', 'Not sure', 'Yes'], index=0)
71
+ tb_prior_Pul = st.selectbox('TB Prior - Pulmonary', ['No', 'Yes'], index=0)
72
+ tb_prior_Extrapul = st.selectbox('TB Prior - Extrapulmonary', ['No', 'Yes'], index=0)
73
+ tb_prior_Unknown = st.selectbox('TB Prior - Unknown', ['No', 'Yes'], index=0)
74
+ hemoptysis = st.selectbox('Hemoptysis', ['No', 'Yes'], index=0)
75
+ weight_loss = st.selectbox('Weight Loss', ['No', 'Yes'], index=0)
76
+ smoke_lweek = st.selectbox('Smoking Last Week', ['No', 'Yes'], index=0)
77
+ fever = st.selectbox('Fever', ['No', 'Yes'], index=0)
78
+ night_sweats = st.selectbox('Night Sweats', ['No', 'Yes'], index=0)
79
+
80
+ if st.button('Predict'):
81
+ audio_data = preprocess_audio(audio_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  clinical_data = preprocess_clinical_data(age, height, weight, reported_cough_dur, heart_rate, temperature,
83
  sex, tb_prior, tb_prior_Pul, tb_prior_Extrapul, tb_prior_Unknown, hemoptysis, weight_loss, smoke_lweek, fever,
84
  night_sweats)
 
99
  st.write('**Prediction:**')
100
  st.write(f"{prediction_text}")
101
  st.write(f"{probability_label}: {result}")
 
 
 
 
 
102
 
103
  if __name__ == '__main__':
104
  main()