Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display playlist page #96

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.secret
__pycache__
node_modules
Binary file added CS 410 Project Proposal.pdf
Binary file not shown.
3,000 changes: 3,000 additions & 0 deletions LyricsFetcher/10000-MTV-Music-Artists-page-1.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions LyricsFetcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Credit to https://gist.github.com/mbejda/9912f7a366c62c1f296c for artiste names
38 changes: 38 additions & 0 deletions LyricsFetcher/lyrics_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pickle
from typing import List
from flair.models import TextClassifier
from flair.data import Sentence
import pandas as pd


def get_data():
song_list = List[dict]
with open('songs.pkl', 'rb') as f:
song_list = pickle.load(f)
df = pd.DataFrame.from_records(song_list)
process_data(df)
return df

def process_data(df):
scores = []
labels = []
textClassifier = TextClassifier.load('en-sentiment')
for lyric in df['lyrics']:
songLyrics = Sentence(lyric)
textClassifier.predict(songLyrics)
classified = songLyrics.labels[0]
scores.append(songLyrics.score)
if "POSITIVE" in str(classified):
labels.append("pos")
elif "NEGATIVE" in str(classified):
labels.append("neg")
else:
labels.append("neu")
final_df = pd.DataFrame({'score': scores, 'label': labels})
final_df = pd.concat([df, final_df], axis=1)

print(final_df)



dataset = get_data()
64 changes: 64 additions & 0 deletions LyricsFetcher/song_fetcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from lyricsgenius.artist import Artist
from requests.exceptions import HTTPError, Timeout
from lyricsgenius import Genius
import pickle
import csv

TOKEN = "<TOKEN>"
TOTAL_ARTISTES = 10 # must be less than 3k

def process_lyrics(lyrics):
lyrics_stored = lyrics.split("\n")
lyrics = ""
for line in lyrics_stored:
if "[" in line and "]" in line:
continue
else:
lyrics+= (line.lower()+". ")
return lyrics


def get_music_by_artiste(artiste, song_count = 10):
song_list = []
try:
genius = Genius(TOKEN, retries=3)
songs = genius.search_artist(artiste, sort="popularity", max_songs=song_count)
if songs is None:
return []

for song in songs.songs:
song_list.append({
"artiste": artiste,
"title": song.full_title,
"thumbnail": song.song_art_image_url,
"lyrics": process_lyrics(song.lyrics)
})
except HTTPError as e:
print(e.errno) # status code
print(e.args[0]) # status code
print(e.args[1]) # error message
except Timeout:
pass
finally:
return song_list

def main():
all_songs = []
with open('10000-MTV-Music-Artists-page-1.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == TOTAL_ARTISTES:
break
if line_count != 0:
print("Getting ", row[0])
songs_from_artiste = get_music_by_artiste(row[0])
all_songs = all_songs + songs_from_artiste
line_count += 1
print(f'Processed {line_count} lines.')

with open('songs.pkl', 'wb') as f:
pickle.dump(all_songs, f)

if __name__ == '__main__':
main()
Binary file added LyricsFetcher/songs.pkl
Binary file not shown.
Binary file added ProjectProgressReport.pdf
Binary file not shown.
96 changes: 94 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,95 @@
# CourseProject
# The Mood Playlist Generator

Please fork this repository and paste the github link of your fork on Microsoft CMT. Detailed instructions are on Coursera under Week 1: Course Project Overview/Week 9 Activities.
To install:
1. `cd app`
2. `pip install -r requirements.txt`
3. `npm install`

To run the application:
1. `cd app`
2. `npm start`

#### Backend Initiatization
1. `cd app`
2. install stuff `pip install -r requirements.txt`
3. Run `uvicorn RocketBE.main:app --reload`
4. go to `http://127.0.0.1:8000/docs`

`POST: URL http://127.0.0.1:8000/get_mood_songs`

Sample Request/Body
```
{
"phrase": "string"
}
```

Sample Response
```
{
"sentiment": "excited",
"score": 0.99,
"playlist": [
{
"artiste": " One Direction ",
"title": "If I Could Fly by One Direction",
"thumbnail": "https://images.genius.com/d1815a034dd35663795e483d8a62ea5f.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " Draaco Aventura ",
"title": "Insaciable by Draaco Aventura",
"thumbnail": "https://images.genius.com/0bfc284e0c63e81511b883bfa4ab2c9b.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " One Direction ",
"title": "Night Changes by One Direction",
"thumbnail": "https://images.rapgenius.com/a8c066965cd804df56261afe172cce2b.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " Drake ",
"title": "Hold On, We're Going Home by Drake (Ft. Majid Jordan)",
"thumbnail": "https://images.rapgenius.com/f545371242592e32983526102bd7b01d.600x600x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " Carrie Underwood ",
"title": "Jesus, Take the Wheel by Carrie Underwood",
"thumbnail": "https://images.genius.com/6da12b47f7f56625a73187f3ab93d562.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " Drake ",
"title": "From Time by Drake (Ft. Jhené Aiko)",
"thumbnail": "https://images.genius.com/6d70f1e6d38e9af4ddb7b3582a40dab8.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " One Direction ",
"title": "Story of My Life by One Direction",
"thumbnail": "https://images.rapgenius.com/87839ab693a21fe86fbb9d2812748705.960x960x1.png",
"link": "https://twitter.com/elon"
},
{
"artiste": " Drake ",
"title": "Hotline Bling by Drake",
"thumbnail": "https://images.genius.com/f3be0158d3a067a81b075686a3a2e63d.1000x1000x1.png",
"link": "https://twitter.com/elon"
},
{
"artiste": " Joey + Rory ",
"title": "I Need Thee Every Hour by Joey + Rory",
"thumbnail": "https://images.genius.com/696da21338fdf225eb42457082f4760a.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
},
{
"artiste": " One Direction ",
"title": "Drag Me Down by One Direction",
"thumbnail": "https://images.rapgenius.com/81f934585e8735158bab36d3cf5d9520.1000x1000x1.jpg",
"link": "https://twitter.com/elon"
}
]
}
```
2 changes: 2 additions & 0 deletions app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_SPOTIFY_API_KEY=e60371614a224640b59c0ac21bd5a616
DANGEROUSLY_DISABLE_HOST_CHECK=true
24 changes: 24 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/**/*/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
16 changes: 16 additions & 0 deletions app/RocketBE/Model/request_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List
from pydantic import BaseModel

class Song(BaseModel):
artiste: str
title: str
thumbnail: str
link: str


class MoodRequest(BaseModel):
phrase: str

class MoodRespond(BaseModel):
sentiment: str
playlist: List[Song]
48 changes: 48 additions & 0 deletions app/RocketBE/SongProcessor/flair_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

import random
from typing import List, Tuple
from RocketBE.Model.request_model import Song
from RocketBE.SongProcessor.processor import SongProcessor


class FlairSentimentAnalyzer(SongProcessor):

def __init__(self) -> None:
super().__init__()
self.process_data()

def process_input(self, user_mood) -> Tuple[List[Song], str]:
random_ten_items = random.sample(super().get_data(), 10)
result: List[Song] = []
for song in random_ten_items:
result.append(
Song(
artiste= song["artiste"],
title= song["title"],
link = "https://twitter.com/elon",
thumbnail = song["thumbnail"]
)
)

return result, "excited"

# return [
# Song(
# artiste= "Ed Sheeran",
# title= "A Team",
# link = "some url",
# thumbnail = "https://w7.pngwing.com/pngs/700/182/png-transparent-ed-sheeran-divide-musician-shape-of-you-others-miscellaneous-tshirt-microphone-thumbnail.png"
# ),
# Song(
# artiste= "Selena Gomez",
# title= "Rare",
# link = "some url",
# thumbnail = "https://integralatampost.s3.amazonaws.com/uploads/article/picture/20581/2020-01-16_16_092020-01-16_16_0920200118_Todo-sobre-el-nuevo-%C3%A1lbum-de-Selena-G%C3%B3mez_-Rare.jpg",
# )
# ]


def process_data(self) -> None:
data: List[dict] = super().get_data()
random_ten_items = random.sample(data, 10)

Loading