In this blog, we'll dive 🌊🤿 into building a Streamlit-based dashboard for analyzing Spotify User Sentiment using Airbyte for data extraction, Motherduck (DuckDB) for storage and querying, and Daytona for streamlined development environments. This project explores how these technologies integrate with Streamlit to create an interactive and insightful data analysis application.
📁 Folder Structure Overview
SPOTIFY-REVIEWS-ANALYSIS
├── .devcontainer
│ ├── devcontainer.json
├── .streamlit
│ ├── config.toml
├── assets
│ ├── main.png
├── src
│ ├── config
│ │ ├── __init__.py
│ │ ├── config.py
│ ├── utils
│ │ ├── __init__.py
│ │ ├── database.py
│ ├── app.py
├── .env
├── venv
├── .gitignore
├── LICENSE.md
├── README.md
├── requirements.txt
- .devcontainer/devcontainer.json: Configures development environment.
- .streamlit/config.toml: Streamlit's UI style and configuration.
- assets: Stores static assets like images.
- src/config/config.py: Handles environment variables.
- src/utils/database.py: Queries data from Motherduck.
- src/app.py: Streamlit dashboard and logic.
- .env: Stores environment variables securely.
👉 Tips On Folder Structure
- SPOTIFY-REVIEWS-ANALYSIS: This is the outer folder of the repository.
- src: This folder contains config and utils for project logic.
☀️ Daytona Integration
Daytona is an open-source Development Environment Manager (DEM) designed to simplify and streamline the process of setting up development environments.
🛠️ Why Daytona?
- Consistency: Ensures uniform development environments across all team members.
- Scalability: Manages multiple environments seamlessly.
- Security: Isolates and secures environments.
- Efficiency: Reduces overhead during setup and switching between environments.
📚 Daytona Setup
- Installation: Follow the official installation guide.
-
Configuration: Create a
daytona.yaml
file with dependencies and environment configurations. - Environment Initialization: Run Daytona commands to set up your development environment.
environment:
name: spotify-reviews-analysis
dependencies:
- python
- pip
scripts:
start: "streamlit run src/app.py"
Daytona ensures every developer has an identical and functional environment for running the project seamlessly.
🎏 Streamlit Setup
Streamlit is an open-source Python library that enables developers to create interactive web apps for data science and machine learning projects.
📜 Code Snippet: Streamlit Core Structure
import streamlit as st
import plotly.express as px
from utils.database import get_reviews_for_sentiment
st.set_page_config(page_title="Spotify Analysis", page_icon="🗳️", layout="wide")
# Title
st.markdown("## 🗳️ Spotify Sentiment Analysis")
# Sidebar
sentiment_type = st.sidebar.selectbox("Sentiment Analysis Type", ["Polarity", "Subjectivity"])
# Fetch and Display Data
reviews_df = get_reviews_for_sentiment()
st.dataframe(reviews_df)
When you run app.py
with streamlit run src/app.py
, the dashboard launches at http://localhost:8501.
📊 Core Logic of Sentiment Analysis
Sentiment analysis is powered by TextBlob to determine the polarity (positive/negative sentiment) and subjectivity (factual/opinionated content) of reviews.
🧠 Sentiment Analysis Function
from textblob import TextBlob
def get_sentiment(text):
blob = TextBlob(str(text))
return blob.sentiment.polarity if sentiment_type == "Polarity" else blob.sentiment.subjectivity
📈 Visualization Example
fig = px.histogram(reviews_df, x='sentiment', title='Sentiment Distribution')
st.plotly_chart(fig)
🦆 Database Integration with Motherduck
🔗 database.py
import duckdb
from config.config import MOTHERDUCK_TOKEN
def get_connection():
return duckdb.connect(f"md:?token={MOTHERDUCK_TOKEN}")
def get_reviews_for_sentiment():
conn = get_connection()
query = """
SELECT content, score FROM spotify_reviews WHERE content IS NOT NULL
"""
return conn.execute(query).fetch_df()
This code fetches Spotify review data securely using MOTHERDUCK_TOKEN stored in .env
through config.py
file.
🗂️ config.py
import os
from dotenv import load_dotenv
load_dotenv()
MOTHERDUCK_TOKEN = os.getenv("MOTHERDUCK_TOKEN")
🔄 Connection Between app.py
and database.py
The app.py
imports get_reviews_for_sentiment
from database.py
, creating a seamless flow of data into the dashboard.
🎯 Conclusion
We successfully built a Spotify Reviews Sentiment Analysis Dashboard using Airbyte, Motherduck, Streamlit, and Daytona. This project demonstrates the power of consistent development environments, robust data storage, and insightful visualization.
👨💻 Check out the complete code on GitHub.
📺 Live PROJECT https://spotify-sentiment-analysis.streamlit.app
Top comments (0)