-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
964 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
venv | ||
.myenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Effect of Music on Mental Health (Community app) | ||
|
||
![music and mental Health](music_and_mental_health.gif) | ||
|
||
Author: @Boadzie | ||
|
||
## Introduction | ||
|
||
> This project aims to investigate the relationship between music and mental health. We will be looking at how different types of music can affect an individual's mood and overall psychological well-being. The dataset from [Kaggle](https://www.kaggle.com/datasets/catherinerasgaitis/mxmh-survey-results) | ||
> | ||
> The ultimate goal is to gain a better understanding of the ways in which music can be used as a tool to promote mental health and well-being. | ||
## Running the project (Dashboard) | ||
|
||
To run the dashboard, do the following: | ||
|
||
1. create a virtual environment with the command: | ||
|
||
```bash | ||
python -m venv .myenv | ||
``` | ||
|
||
2. Activate the virtual environment | ||
|
||
```bash | ||
source .myenv/bin/activate | ||
``` | ||
|
||
3. Install dependencies | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
4. Navigate to the `src` folder and run: | ||
|
||
```bash | ||
wave run src/app.py | ||
``` | ||
|
||
5. Point your browser to `http://localhost:10101` to view the app. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
h2o-wave==0.24.2 | ||
pandas==1.5.2 | ||
plotly==5.11.0 | ||
siuba==0.4.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from h2o_wave import Q, ui, main, app | ||
import pandas as pd | ||
from siuba import * | ||
from .charts import show_table, streaming_service, fav_age_effect, fav_depression, fav_insomnia | ||
|
||
|
||
# read the data anc cover | ||
music = pd.read_csv("music_mental_survey_clean.csv") | ||
music = music >> select(~_["Unnamed: 0"]) # remove unwanted column | ||
|
||
|
||
@app("/") | ||
async def serve(q: Q): | ||
q.page["meta"] = ui.meta_card( | ||
box="", | ||
themes=[ | ||
ui.theme( | ||
name="cool7", | ||
primary="#ffffff", | ||
text="#ffffff", | ||
card="#111111", | ||
page="#ffffff", | ||
) | ||
], | ||
theme="cool7", | ||
) | ||
q.page["header"] = ui.header_card( | ||
box=("1 1 10 1"), | ||
icon="HealthRefresh", | ||
color="card", | ||
title="Music's effect on Mental Health", | ||
subtitle="Can music impact mental health? Let's find out", | ||
) | ||
q.page["table"] = ui.form_card( | ||
box=("1 2 3 5"), | ||
title="Music and Mental Condition Dataset", | ||
items=[await show_table(df=music)], | ||
) | ||
|
||
q.page["streaming_service"] = ui.frame_card( | ||
box=("4 2 3 5"), | ||
title="Most popular streaming service", | ||
content=await streaming_service(df=music), | ||
) | ||
|
||
q.page["fav_depression"] = ui.frame_card( | ||
box=("7 2 4 5"), | ||
title="", | ||
content=await fav_depression(df=music), | ||
) | ||
|
||
q.page["fav_age_effect"] = ui.frame_card( | ||
box=("1 7 5 5"), | ||
title="", | ||
content=await fav_age_effect(df=music), | ||
) | ||
|
||
q.page["fav_insomnia"] = ui.frame_card( | ||
box=("6 7 5 5"), | ||
title="", | ||
content=await fav_insomnia(df=music), | ||
) | ||
|
||
q.page["foot"] = ui.markdown_card( | ||
box="1 12 10 1", | ||
title="", | ||
content="""<br/>**[Daniel Boadzie](https://www.linkedin.com/in/boadzie/) - | ||
The dataset for this project was obtained from [kaggle](https://www.kaggle.com/code/totoro29/music-and-mental-condition/notebook)** | ||
""", | ||
) | ||
|
||
await q.page.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from h2o_wave import Q, ui | ||
from siuba import * | ||
from siuba.siu import call | ||
import plotly.express as px | ||
import plotly.io as pio | ||
from plotly import graph_objects as go | ||
|
||
pio.templates.default = "plotly_dark" | ||
|
||
|
||
def update_chart(fig): | ||
|
||
return fig.update( | ||
layout=go.Layout(margin=dict(t=40, r=0, b=40, l=0), legend=dict(yanchor="top", y=0.95, xanchor="left", x=0.01)) | ||
) | ||
|
||
|
||
# show table of data | ||
async def show_table(df): | ||
return ui.table( | ||
name="table", | ||
height="390px", | ||
# Add pagination attribute to make your table paginated. | ||
pagination=ui.table_pagination(total_rows=100, rows_per_page=5), | ||
events=["page_change"], | ||
columns=[ui.table_column(name=x, label=x) for x in df.columns.tolist()], | ||
rows=[ui.table_row(name=str(i), cells=list(map(str, df.values.tolist()[i]))) for i in df.index[0:100]], | ||
) | ||
|
||
|
||
async def age_hist(df): | ||
fig = df >> call(px.histogram, x="age", data_frame=_, labels={"age": "Age"}) | ||
update_chart(fig) | ||
html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs="cdn") | ||
return html | ||
|
||
|
||
async def streaming_service(df): | ||
fig = df >> call( | ||
px.histogram, | ||
x="primary_streaming_service", | ||
data_frame=_, | ||
labels={"primary_streaming_service": "Primary Streaming Service"}, | ||
) | ||
fig.update_xaxes(categoryorder="total descending") | ||
update_chart(fig) | ||
html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs="cdn") | ||
return html | ||
|
||
|
||
async def fav_age_effect(df): | ||
fig = df >> call( | ||
px.histogram, | ||
x="fav_genre", | ||
y="age", | ||
color="music_effects", | ||
data_frame=_, | ||
text_auto=True, | ||
histfunc="avg", | ||
barmode="group", | ||
title="Music Effect on Listeners - Age", | ||
labels={"fav_genre": "Fav Genre", "age": "Age"}, | ||
) | ||
|
||
update_chart(fig) | ||
html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs="cdn") | ||
return html | ||
|
||
|
||
async def fav_depression(df): | ||
fig = df >> call( | ||
px.histogram, | ||
x="fav_genre", | ||
y="depression", | ||
color="music_effects", | ||
data_frame=_, | ||
text_auto=True, | ||
histfunc="avg", | ||
barmode="group", | ||
title="Music Effect on Listeners - Depression", | ||
labels={"fav_genre": "Fav Genre", "depression": "Depression"}, | ||
) | ||
|
||
fig.update_yaxes(title="Depression", range=[0, 10]) | ||
update_chart(fig) | ||
html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs="cdn") | ||
return html | ||
|
||
|
||
async def fav_insomnia(df): | ||
fig = df >> call( | ||
px.histogram, | ||
y="insomnia", | ||
x="fav_genre", | ||
color="music_effects", | ||
data_frame=_, | ||
text_auto=True, | ||
histfunc="avg", | ||
barmode="group", | ||
title="Music Effect on Listeners - Insomnia", | ||
labels={"fav_genre": "Fav Genre", "insomnia": "Insomnia"}, | ||
) | ||
|
||
fig.update_yaxes(title="Insomnia", range=[0, 10]) | ||
update_chart(fig) | ||
html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs="cdn") | ||
return html |