Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,40 +7,39 @@ API_URL = "https://api-inference.huggingface.co/models/MIT/ast-finetuned-audiose
|
|
7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
8 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
9 |
|
10 |
-
# Function to send audio file to the Hugging Face
|
11 |
-
def
|
12 |
-
with open(
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
return response.json()
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
"Labrador Barking": "labrador-barking.mp3",
|
20 |
-
"Tolling Bell": "tolling-bell.mp3",
|
21 |
-
"Airplane Landing": "airplane-landing.mp3",
|
22 |
-
"Old Car Engine": "old-car-engine.mp3",
|
23 |
-
"Hard Shoes": "hard_shoes.mp3",
|
24 |
-
"Alien Spaceship": "alien-spaceship.mp3",
|
25 |
-
}
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
results = query(audio_file_path)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
8 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
9 |
|
10 |
+
# Function to send the audio file to the Hugging Face API and get the classification result
|
11 |
+
def classify_audio(audio_file_path):
|
12 |
+
with open(audio_file_path, "rb") as audio_file:
|
13 |
+
response = requests.post(
|
14 |
+
"https://api-inference.huggingface.co/models/MIT/ast-finetuned-audioset-10-10-0.4593",
|
15 |
+
headers=headers,
|
16 |
+
files={"file": audio_file}
|
17 |
+
)
|
18 |
return response.json()
|
19 |
|
20 |
+
# Streamlit interface
|
21 |
+
st.title("Audio Classifier")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Define the folder where your audio files are located
|
24 |
+
audio_folder = "audio_files"
|
25 |
|
26 |
+
# List the audio files in the folder
|
27 |
+
audio_files = os.listdir(audio_folder)
|
28 |
+
audio_file_options = [f for f in audio_files if f.endswith(('.mp3', '.wav'))]
|
29 |
|
30 |
+
# Dropdown to select an audio file
|
31 |
+
selected_file = st.selectbox("Select an audio file:", audio_file_options)
|
|
|
32 |
|
33 |
+
# Button to classify the selected audio file
|
34 |
+
if st.button("Classify"):
|
35 |
+
# Get the full path of the selected audio file
|
36 |
+
audio_file_path = os.path.join(audio_folder, selected_file)
|
37 |
+
|
38 |
+
# Show the audio player
|
39 |
+
st.audio(audio_file_path)
|
40 |
+
|
41 |
+
# Get and display the classification results
|
42 |
+
results = classify_audio(audio_file_path)
|
43 |
+
st.write("Results:")
|
44 |
+
for result in results:
|
45 |
+
st.write(f"Label: {result['label']}, Confidence: {result['score']:.2f}")
|