File size: 1,770 Bytes
9833711
44209c6
9833711
 
44209c6
 
 
 
9833711
f197f2f
 
 
 
 
 
 
 
0b2245a
9833711
f197f2f
 
9833711
f197f2f
 
9833711
f197f2f
0b2245a
 
9833711
f197f2f
 
9833711
368c17b
 
 
 
 
 
 
 
f197f2f
 
 
 
 
 
 
 
 
 
 
 
1eea0e2
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
import requests
import os

# Hugging Face API setup
API_URL = "https://api-inference.huggingface.co/models/MIT/ast-finetuned-audioset-10-10-0.4593"
HF_TOKEN = os.getenv("HF_TOKEN")
headers = {"Authorization": f"Bearer {HF_TOKEN}"} 

# Function to send the audio file to the Hugging Face API and get the classification result
def classify_audio(audio_file_path):
    with open(audio_file_path, "rb") as audio_file:
        response = requests.post(
            "https://api-inference.huggingface.co/models/MIT/ast-finetuned-audioset-10-10-0.4593",
            headers=headers,
            files={"file": audio_file}
        )
    return response.json()

# Streamlit interface
st.title("Audio Classifier")

# Define the folder where your audio files are located
audio_folder = "audio_files"

# List the audio files in the folder
audio_files = os.listdir(audio_folder)
audio_file_options = [f for f in audio_files if f.endswith(('.mp3', '.wav'))]

# Dropdown to select an audio file
selected_file = st.selectbox("Select an audio file:", audio_file_options)

import transformers
import tensorflow as tf

st.write(f"Streamlit version: {st.__version__}")
st.write(f"Transformers version: {transformers.__version__}")
st.write(f"TensorFlow version: {tf.__version__}")


# Button to classify the selected audio file
if st.button("Classify"):
    # Get the full path of the selected audio file
    audio_file_path = os.path.join(audio_folder, selected_file)
    
    # Show the audio player
    st.audio(audio_file_path)
    
    # Get and display the classification results
    results = classify_audio(audio_file_path)
    st.write("Results:")
    for result in results:
        st.write(f"Label: {result['label']}, Confidence: {result['score']:.2f}")