Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- app.py +49 -0
- artifact.wav +0 -0
- config.py +2 -0
- extra_hystole.wav +0 -0
- extra_systole.wav +0 -0
- murmur.wav +0 -0
- normal.wav +0 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
import torchaudio
|
4 |
+
from config import MODEL_ID
|
5 |
+
|
6 |
+
# Load the model and pipeline using the model_id variable
|
7 |
+
pipe = pipeline("audio-classification", model=MODEL_ID)
|
8 |
+
|
9 |
+
def classify_audio(filepath):
|
10 |
+
preds = pipe(filepath)
|
11 |
+
outputs = {}
|
12 |
+
for p in preds:
|
13 |
+
outputs[p["label"]] = p["score"]
|
14 |
+
return outputs
|
15 |
+
|
16 |
+
# Streamlit app layout
|
17 |
+
st.title("Heartbeat Sound Classification")
|
18 |
+
|
19 |
+
# File uploader for audio files
|
20 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
|
21 |
+
|
22 |
+
if uploaded_file is not None:
|
23 |
+
# Load and display the audio file
|
24 |
+
audio_bytes = uploaded_file.read()
|
25 |
+
st.audio(audio_bytes, format='audio/wav')
|
26 |
+
|
27 |
+
# Save the uploaded file to a temporary location
|
28 |
+
with open("temp_audio_file.wav", "wb") as f:
|
29 |
+
f.write(audio_bytes)
|
30 |
+
|
31 |
+
# Classify the audio file
|
32 |
+
st.write("Classifying the audio...")
|
33 |
+
results = classify_audio("temp_audio_file.wav")
|
34 |
+
|
35 |
+
# Display the classification results
|
36 |
+
st.write("Classification results:")
|
37 |
+
for label, score in results.items():
|
38 |
+
st.write(f"{label}: {score:.4f}")
|
39 |
+
|
40 |
+
# Examples of audio files for classification
|
41 |
+
st.write("Examples:")
|
42 |
+
examples = ['normal.wav', 'murmur.wav', 'extra_systole.wav', 'extra_hystole.wav', 'artifact.wav']
|
43 |
+
for example in examples:
|
44 |
+
st.write(example)
|
45 |
+
audio_bytes = open(example, 'rb').read()
|
46 |
+
st.audio(audio_bytes, format='audio/wav')
|
47 |
+
results = classify_audio(example)
|
48 |
+
for label, score in results.items():
|
49 |
+
st.write(f"{label}: {score:.4f}")
|
artifact.wav
ADDED
Binary file (794 kB). View file
|
|
config.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# config.py
|
2 |
+
MODEL_ID = "arham061/distilhubert-finetuned-PASCAL_Dataset_Augmented"
|
extra_hystole.wav
ADDED
Binary file (794 kB). View file
|
|
extra_systole.wav
ADDED
Binary file (47.9 kB). View file
|
|
murmur.wav
ADDED
Binary file (42.4 kB). View file
|
|
normal.wav
ADDED
Binary file (36.7 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
transformers
|