Spaces:
Sleeping
Sleeping
j-tobias
commited on
Commit
·
ee7c3ab
1
Parent(s):
c3f8d07
added second tab
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import os
|
|
8 |
example_dir = "Examples"
|
9 |
example_files = [os.path.join(example_dir, f) for f in os.listdir(example_dir) if f.endswith(('.wav', '.mp3', '.ogg'))]
|
10 |
|
11 |
-
|
12 |
def getBeats(audiodata:np.ndarray, sr:int):
|
13 |
# Compute onset envelope
|
14 |
onset_env = librosa.onset.onset_strength(y=audiodata, sr=sr)
|
@@ -56,7 +56,7 @@ def plotCombined(audiodata, sr):
|
|
56 |
|
57 |
return fig
|
58 |
|
59 |
-
def
|
60 |
# Extract audio data and sample rate
|
61 |
sr, audiodata = audio
|
62 |
|
@@ -100,43 +100,62 @@ def analyze(audio:gr.Audio):
|
|
100 |
- Beats: {beattimes}
|
101 |
"""
|
102 |
return results, spectogram_wave
|
|
|
|
|
103 |
|
|
|
104 |
|
105 |
|
106 |
-
with gr.Blocks() as app:
|
107 |
|
108 |
-
|
109 |
|
110 |
gr.Markdown("# Heartbeat")
|
111 |
gr.Markdown("This App helps to analyze and extract Information from Heartbeats")
|
112 |
gr.Markdown("""
|
113 |
-
- Beat (mean)
|
114 |
-
-
|
115 |
-
- mean - herzschlag
|
116 |
- mean - herzschlag (synthesised) - Bild (Wave & Spectogram)
|
117 |
-
- S1, S2 - mean
|
118 |
- FFT & Mel Spectogram
|
119 |
- Plot of Wave & Spectogram (Beats annotated)
|
120 |
""")
|
121 |
|
122 |
-
|
123 |
-
label="Audio of a Heartbeat",
|
124 |
-
sources="upload")
|
125 |
-
|
126 |
-
analyzebtn = gr.Button("analyze")
|
127 |
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
130 |
|
131 |
-
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
|
142 |
if __name__ == "__main__":
|
|
|
8 |
example_dir = "Examples"
|
9 |
example_files = [os.path.join(example_dir, f) for f in os.listdir(example_dir) if f.endswith(('.wav', '.mp3', '.ogg'))]
|
10 |
|
11 |
+
# HELPER FUNCTIONS FOR SINGLE AUDIO ANALYSIS
|
12 |
def getBeats(audiodata:np.ndarray, sr:int):
|
13 |
# Compute onset envelope
|
14 |
onset_env = librosa.onset.onset_strength(y=audiodata, sr=sr)
|
|
|
56 |
|
57 |
return fig
|
58 |
|
59 |
+
def analyze_single(audio:gr.Audio):
|
60 |
# Extract audio data and sample rate
|
61 |
sr, audiodata = audio
|
62 |
|
|
|
100 |
- Beats: {beattimes}
|
101 |
"""
|
102 |
return results, spectogram_wave
|
103 |
+
#-----------------------------------------------
|
104 |
+
#-----------------------------------------------
|
105 |
|
106 |
+
# HELPER FUNCTIONS FOR DUAL AUDIO ANALYSIS
|
107 |
|
108 |
|
|
|
109 |
|
110 |
+
with gr.Blocks() as app:
|
111 |
|
112 |
gr.Markdown("# Heartbeat")
|
113 |
gr.Markdown("This App helps to analyze and extract Information from Heartbeats")
|
114 |
gr.Markdown("""
|
115 |
+
- Beat (mean) (average heartbeat duration)
|
116 |
+
- S1, S2 (mean) (average S1,S2 duration)
|
|
|
117 |
- mean - herzschlag (synthesised) - Bild (Wave & Spectogram)
|
|
|
118 |
- FFT & Mel Spectogram
|
119 |
- Plot of Wave & Spectogram (Beats annotated)
|
120 |
""")
|
121 |
|
122 |
+
with gr.Tab("Single Audio"):
|
|
|
|
|
|
|
|
|
123 |
|
124 |
+
audiofile = gr.Audio(
|
125 |
+
label="Audio of a Heartbeat",
|
126 |
+
sources="upload")
|
127 |
+
|
128 |
+
analyzebtn = gr.Button("analyze")
|
129 |
|
130 |
+
results = gr.Markdown()
|
131 |
+
spectogram_wave = gr.Plot()
|
132 |
|
133 |
+
analyzebtn.click(analyze_single, audiofile, [results, spectogram_wave])
|
134 |
+
|
135 |
+
gr.Examples(
|
136 |
+
examples=example_files,
|
137 |
+
inputs=audiofile,
|
138 |
+
outputs=[results, spectogram_wave],
|
139 |
+
fn=analyze_single,
|
140 |
+
cache_examples=False
|
141 |
+
)
|
142 |
+
|
143 |
+
with gr.Tab("Two Audios"):
|
144 |
+
|
145 |
+
with gr.Row():
|
146 |
+
|
147 |
+
audioone = gr.Audio(
|
148 |
+
label="Audio of a Heartbeat",
|
149 |
+
sources="upload")
|
150 |
+
audiotwo = gr.Audio(
|
151 |
+
label="Audio of a Heartbeat",
|
152 |
+
sources="upload")
|
153 |
+
|
154 |
+
analyzebtn2 = gr.Button("analyze & compare")
|
155 |
+
|
156 |
+
with gr.Accordion("Results",open=False):
|
157 |
+
results2 = gr.Markdown()
|
158 |
+
spectogram_wave2 = gr.Plot()
|
159 |
|
160 |
|
161 |
if __name__ == "__main__":
|