Spaces:
Running
Running
j-tobias
commited on
Commit
•
a7f7a4d
1
Parent(s):
f7d4d0d
initial commit
Browse files- app.py +80 -0
- requirements.txt +21 -0
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import librosa
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
def analyze(audio:gr.Audio):
|
8 |
+
# Extract audio data and sample rate
|
9 |
+
sr, audio_data = audio
|
10 |
+
|
11 |
+
# Ensure audio_data is a numpy array
|
12 |
+
if not isinstance(audio_data, np.ndarray):
|
13 |
+
audio_data = np.array(audio_data)
|
14 |
+
|
15 |
+
# Check if audio is mono or stereo
|
16 |
+
if len(audio_data.shape) > 1:
|
17 |
+
# If stereo, convert to mono by averaging channels
|
18 |
+
audio_data = np.mean(audio_data, axis=1)
|
19 |
+
|
20 |
+
audio_data = np.astype(audio_data, np.float16)
|
21 |
+
|
22 |
+
# Now you have:
|
23 |
+
# - audio_data: a 1D numpy array containing the audio samples
|
24 |
+
# - sr: the sample rate of the audio
|
25 |
+
|
26 |
+
# Your analysis code goes here
|
27 |
+
# For example, you could print basic information:
|
28 |
+
print(f"Audio length: {len(audio_data) / sr:.2f} seconds")
|
29 |
+
print(f"Sample rate: {sr} Hz")
|
30 |
+
|
31 |
+
zcr = librosa.feature.zero_crossing_rate(audio_data)[0]
|
32 |
+
print(f"Mean Zero Crossing Rate: {np.mean(zcr):.4f}")
|
33 |
+
|
34 |
+
# Calculate RMS Energy
|
35 |
+
rms = librosa.feature.rms(y=audio_data)[0]
|
36 |
+
print(f"Mean RMS Energy: {np.mean(rms):.4f}")
|
37 |
+
|
38 |
+
# Return your analysis results
|
39 |
+
|
40 |
+
results = f"""
|
41 |
+
- Audio length: {len(audio_data) / sr:.2f} seconds
|
42 |
+
- Sample rate: {sr} Hz
|
43 |
+
- Mean Zero Crossing Rate: {np.mean(zcr):.4f}
|
44 |
+
- Mean RMS Energy: {np.mean(rms):.4f}
|
45 |
+
"""
|
46 |
+
return results
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
with gr.Blocks() as app:
|
51 |
+
|
52 |
+
gr.Markdown("🚨 This Project is still in works")
|
53 |
+
|
54 |
+
gr.Markdown("# Heartbeat")
|
55 |
+
gr.Markdown("This App helps to analyze and extract Information from Heartbeats")
|
56 |
+
gr.Markdown("""
|
57 |
+
- Beat (mean)
|
58 |
+
- normalised
|
59 |
+
- mean - herzschlag
|
60 |
+
- mean - herzschlag (synthesised) - Bild (Wave & Spectogram)
|
61 |
+
- S1, S2 - mean
|
62 |
+
- FFT & Mel Spectogram
|
63 |
+
- Plot of Wave & Spectogram (Beats annotated)
|
64 |
+
""")
|
65 |
+
|
66 |
+
audiofile = gr.Audio(
|
67 |
+
label="Audio of a Heartbeat",
|
68 |
+
sources="upload")
|
69 |
+
|
70 |
+
analyzebtn = gr.Button("analyze")
|
71 |
+
|
72 |
+
results = gr.Markdown()
|
73 |
+
|
74 |
+
analyzebtn.click(analyze, audiofile, results)
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
if __name__ == "__main__":
|
80 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file may be used to create an environment using:
|
2 |
+
# $ conda create --name <env> --file <this file>
|
3 |
+
# platform: osx-arm64
|
4 |
+
@EXPLICIT
|
5 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/bzip2-1.0.8-h80987f9_6.conda
|
6 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/ca-certificates-2024.7.2-hca03da5_0.conda
|
7 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/libcxx-14.0.6-h848a8c0_0.conda
|
8 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/libffi-3.4.4-hca03da5_1.conda
|
9 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/ncurses-6.4-h313beb8_0.conda
|
10 |
+
https://repo.anaconda.com/pkgs/main/noarch/tzdata-2024a-h04d1e81_0.conda
|
11 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/xz-5.4.6-h80987f9_1.conda
|
12 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/zlib-1.2.13-h18a0788_1.conda
|
13 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/expat-2.6.3-h313beb8_0.conda
|
14 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/openssl-3.0.15-h80987f9_0.conda
|
15 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/readline-8.2-h1a28f6b_0.conda
|
16 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/tk-8.6.14-h6ba3021_0.conda
|
17 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/sqlite-3.45.3-h80987f9_0.conda
|
18 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/python-3.12.3-h99e199e_1.conda
|
19 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/setuptools-72.1.0-py312hca03da5_0.conda
|
20 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/wheel-0.44.0-py312hca03da5_0.conda
|
21 |
+
https://repo.anaconda.com/pkgs/main/osx-arm64/pip-24.2-py312hca03da5_0.conda
|