genre_classify / app.py
azeus
adding analysis
c00ec95
raw
history blame
1.9 kB
import streamlit as st
import numpy as np
# Page setup
st.title("🎵 Music Genre Classifier")
st.write("Upload an audio file to analyze its genre")
# Create two columns for better layout
col1, col2 = st.columns(2)
with col1:
# File upload
audio_file = st.file_uploader("Upload an audio file (MP3, WAV)", type=['mp3', 'wav'])
if audio_file is not None:
# Display audio player
st.audio(audio_file)
st.success("File uploaded successfully!")
# Add a classify button
if st.button("Classify Genre"):
with st.spinner("Analyzing..."):
# Simulate genre classification (we'll replace this with real model later)
genres = ["Rock", "Pop", "Hip Hop", "Classical", "Jazz"]
confidences = np.random.dirichlet(np.ones(5)) # Random probabilities that sum to 1
# Show results
st.write("### Genre Analysis Results:")
for genre, confidence in zip(genres, confidences):
st.write(f"{genre}: {confidence:.2%}")
# Show top prediction
top_genre = genres[np.argmax(confidences)]
st.write(f"**Predicted Genre:** {top_genre}")
with col2:
# Display some tips and information
st.write("### Tips for best results:")
st.write("- Upload files in MP3 or WAV format")
st.write("- Ensure good audio quality")
st.write("- Try to upload songs without too much background noise")
st.write("- Ideal length: 10-30 seconds")
# Add a sample counter
if 'analyzed_count' not in st.session_state:
st.session_state.analyzed_count = 0
if audio_file is not None:
st.session_state.analyzed_count += 1
st.write(f"Songs analyzed this session: {st.session_state.analyzed_count}")
# Footer
st.markdown("---")
st.write("Made with ❤️ using Streamlit")