Skip to content

Commit

Permalink
Merge pull request #30 from polskiXO/1-mood2spotifyrec-project
Browse files Browse the repository at this point in the history
1 mood2spotifyrec project
  • Loading branch information
polskiTran authored Apr 23, 2024
2 parents beefbde + 282bee2 commit 3b9bfdb
Show file tree
Hide file tree
Showing 20 changed files with 2,440 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/Mood2SpotifyRec_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run Unit Test via Pytest

on:
push:
paths:
- "projects/Mood2SpotifyRec/**/*"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["^3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install pytest
pip install pytest-cov
- name: Test with pytest
run: |
pytest projects/NatLang2Latex -v -s
25 changes: 25 additions & 0 deletions projects/Mood2SpotifyRec/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.10-bookworm",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
5 changes: 5 additions & 0 deletions projects/Mood2SpotifyRec/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"

SPOTIPY_CLIENT_ID="YOUR_SPOTIFY_CLIENT_ID"
SPOTIPY_CLIENT_SECRET="YOUR_SPOTIFY_CLIENT_SECRET"
SPOTIPY_REDIRECT_URI="YOUR_SPOTIFY_REDIRECT_URI"
Empty file.
200 changes: 200 additions & 0 deletions projects/Mood2SpotifyRec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


## Mac git ignore
# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/macos
3 changes: 3 additions & 0 deletions projects/Mood2SpotifyRec/.streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Forcing light theme on streamlit app
[theme]
base="dark"
32 changes: 32 additions & 0 deletions projects/Mood2SpotifyRec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Mood2SpotifyRec

Quick app to use the user's mood input as generation data to a Spotify playlist.

# Setup

Have poetry installed. Run

```terminal
poetry install
```

## Get spotify client id and secret

follow this tutorial: https://support.heateor.com/get-spotify-client-id-client-secret/

> Note that for the redirect URI, enter "http://localhost:8888/callback"
## Running the webapp

in command line, export your client id and secret

```terminal
export SPOTIPY_CLIENT_ID="your client id goes here"
export SPOTIPY_CLIENT_SECRET="your client secret goes here"
```

then run

```terminal
streamlit run main.py
```
51 changes: 51 additions & 0 deletions projects/Mood2SpotifyRec/SeedData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class SeedData:
def __init__(
self,
seed_genres=None,
seed_artists=None,
target_valence=None,
target_energy=None,
target_danceability=None,
target_acousticness=None,
):
self.seed_genres = seed_genres if seed_genres is not None else []
self.seed_artists = seed_artists if seed_artists is not None else []
self.target_valence = target_valence
self.target_energy = target_energy
self.target_danceability = target_danceability
self.target_acousticness = target_acousticness

def get_test_seed_data(self):
return SeedData(
seed_genres=["indie", "rock"],
seed_artists=[
"4NHQUGzhtTLFvgF5SZesLK"
], # Example artist ID for Tame Impala
# seed_tracks=["0c6xIDDpzE81m2q797ordA"], # Example track ID
target_valence=0.5,
target_energy=0.8,
target_danceability=0.7,
target_acousticness=0.3,
)

def to_seed_data(self, in_metric):
return SeedData(
seed_genres=["indie", "pop"],
seed_artists=[
"4NHQUGzhtTLFvgF5SZesLK"
], # Example artist ID for Tame Impala
target_valence=in_metric["valence"],
target_energy=in_metric["energy"],
target_danceability=in_metric["danceability"],
target_acousticness=in_metric["acousticness"],
)

def view_seed_data(self):
return {
"seed_genres": self.seed_genres,
"seed_artists": self.seed_artists,
"target_valence": self.target_valence,
"target_energy": self.target_energy,
"target_danceability": self.target_danceability,
"target_acousticness": self.target_acousticness,
}
Loading

0 comments on commit 3b9bfdb

Please sign in to comment.