mistermprah commited on
Commit
0875d49
1 Parent(s): 5c30903

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -34
app.py CHANGED
@@ -19,37 +19,98 @@ def classify_audio(filepath):
19
  # Streamlit app layout
20
  st.title("Heartbeat Sound Classification")
21
 
22
- # Add custom CSS for styling
23
- st.markdown(
24
- """
25
- <style>
26
- body {
27
- background-color: #f0f4c3; /* Light green background */
28
- }
29
- .stApp {
30
- color: #006064; /* Dark sea blue text */
31
- }
32
- .stButton > button {
33
- background-color: #006064; /* Dark sea blue button background */
34
- color: white; /* White text */
35
- }
36
- .stButton > button:hover {
37
- background-color: #004d40; /* Darker sea blue on hover */
38
- }
39
- .stFileUpload > div {
40
- background-color: #006064; /* Dark sea blue file uploader background */
41
- color: white; /* White text */
42
- border-radius: 5px;
43
- padding: 10px;
44
- }
45
- .stFileUpload > div:hover {
46
- background-color: #004d40; /* Darker sea blue on hover */
47
- }
48
- </style>
49
- """,
50
- unsafe_allow_html=True
51
  )
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # File uploader for audio files
54
  uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
55
 
@@ -79,10 +140,8 @@ st.write("Audio Test Samples:")
79
  examples = ['normal.wav', 'murmur.wav', 'extra_systole.wav', 'extra_hystole.wav', 'artifact.wav']
80
 
81
  # Determine the number of columns based on the screen size
82
- if st.session_state.get("is_mobile", False):
83
- num_columns = 1 # Single column for mobile view
84
- else:
85
- num_columns = 3 # Multiple columns for desktop view
86
 
87
  # Arrange buttons in the columns
88
  cols = st.columns(num_columns)
@@ -95,7 +154,7 @@ for idx, example in enumerate(examples):
95
  col.audio(audio_bytes, format='audio/wav')
96
  results = classify_audio(example)
97
  col.write("Results:")
98
- results_str = "\n".join([f"{label}: {score:.2f}" for label, score in results.items()])
99
  col.text(results_str)
100
 
101
  # JavaScript to detect if the user is on a mobile device
 
19
  # Streamlit app layout
20
  st.title("Heartbeat Sound Classification")
21
 
22
+ # Theme selection
23
+ theme = st.sidebar.selectbox(
24
+ "Select Theme",
25
+ ["Light Green", "Light Blue", "Dark Green", "Dark Blue"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  )
27
 
28
+ # Add custom CSS for styling based on the selected theme
29
+ if theme == "Light Green":
30
+ st.markdown(
31
+ """
32
+ <style>
33
+ body {
34
+ background-color: #e8f5e9; /* Light green background */
35
+ }
36
+ .stApp {
37
+ color: #004d40; /* Dark green text */
38
+ }
39
+ .stButton > button, .stFileUpload > div {
40
+ background-color: #004d40; /* Dark green button and file uploader background */
41
+ color: white; /* White text */
42
+ }
43
+ .stButton > button:hover, .stFileUpload > div:hover {
44
+ background-color: #00332c; /* Darker green on hover */
45
+ }
46
+ </style>
47
+ """,
48
+ unsafe_allow_html=True
49
+ )
50
+ elif theme == "Light Blue":
51
+ st.markdown(
52
+ """
53
+ <style>
54
+ body {
55
+ background-color: #e0f7fa; /* Light blue background */
56
+ }
57
+ .stApp {
58
+ color: #006064; /* Dark blue text */
59
+ }
60
+ .stButton > button, .stFileUpload > div {
61
+ background-color: #006064; /* Dark blue button and file uploader background */
62
+ color: white; /* White text */
63
+ }
64
+ .stButton > button:hover, .stFileUpload > div:hover {
65
+ background-color: #004d40; /* Darker blue on hover */
66
+ }
67
+ </style>
68
+ """,
69
+ unsafe_allow_html=True
70
+ )
71
+ elif theme == "Dark Green":
72
+ st.markdown(
73
+ """
74
+ <style>
75
+ body {
76
+ background-color: #1b5e20; /* Dark green background */
77
+ }
78
+ .stApp {
79
+ color: #a5d6a7; /* Light green text */
80
+ }
81
+ .stButton > button, .stFileUpload > div {
82
+ background-color: #004d40; /* Dark green button and file uploader background */
83
+ color: white; /* White text */
84
+ }
85
+ .stButton > button:hover, .stFileUpload > div:hover {
86
+ background-color: #00332c; /* Darker green on hover */
87
+ }
88
+ </style>
89
+ """,
90
+ unsafe_allow_html=True
91
+ )
92
+ elif theme == "Dark Blue":
93
+ st.markdown(
94
+ """
95
+ <style>
96
+ body {
97
+ background-color: #0d47a1; /* Dark blue background */
98
+ }
99
+ .stApp {
100
+ color: #bbdefb; /* Light blue text */
101
+ }
102
+ .stButton > button, .stFileUpload > div {
103
+ background-color: #006064; /* Dark blue button and file uploader background */
104
+ color: white; /* White text */
105
+ }
106
+ .stButton > button:hover, .stFileUpload > div:hover {
107
+ background-color: #004d40; /* Darker blue on hover */
108
+ }
109
+ </style>
110
+ """,
111
+ unsafe_allow_html=True
112
+ )
113
+
114
  # File uploader for audio files
115
  uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
116
 
 
140
  examples = ['normal.wav', 'murmur.wav', 'extra_systole.wav', 'extra_hystole.wav', 'artifact.wav']
141
 
142
  # Determine the number of columns based on the screen size
143
+ is_mobile = st.session_state.get("is_mobile", False)
144
+ num_columns = 1 if is_mobile else 3
 
 
145
 
146
  # Arrange buttons in the columns
147
  cols = st.columns(num_columns)
 
154
  col.audio(audio_bytes, format='audio/wav')
155
  results = classify_audio(example)
156
  col.write("Results:")
157
+ results_str = "\n.join([f"{label}: {score:.2f}" for label, score in results.items()])
158
  col.text(results_str)
159
 
160
  # JavaScript to detect if the user is on a mobile device