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}")