|
|
|
import streamlit as st |
|
from transformers import pipeline |
|
import os |
|
import tensorflow as tf |
|
|
|
|
|
st.title('Music Genre Classification') |
|
|
|
|
|
audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "flac"]) |
|
|
|
if audio_file is not None: |
|
|
|
if not os.path.exists("temp_audio"): |
|
os.makedirs("temp_audio") |
|
|
|
with open(os.path.join("temp_audio", audio_file.name), "wb") as f: |
|
f.write(audio_file.getbuffer()) |
|
|
|
|
|
audio_path = os.path.join("temp_audio", audio_file.name) |
|
|
|
|
|
st.text("Classifying the audio file... Please wait.") |
|
|
|
|
|
pipe = pipeline("audio-classification", model="sandychoii/distilhubert-finetuned-gtzan-audio-classification") |
|
|
|
|
|
result = pipe(audio_path) |
|
|
|
|
|
st.subheader("Classification Results:") |
|
for label in result: |
|
st.write(f"**Genre**: {label['label']} | **Confidence**: {label['score']:.4f}") |
|
|
|
|
|
st.audio(audio_file) |
|
|