Using music to uplift mood and alleviate depression Music can be used to uplift one's mood and alleviate depression, as depicted in this article:


  In Darkness Visible: A Memoir of Madness American author William
  Styron's autobiographical account of his struggle with depression he
  describes how in desperation he planned to shoot himself, but at the
  last minute he heard the music of the German composer Johannes Brahms
  and this saved him. 
  
  His life began to mean something and he found solace in the
  melancholic and uplifting moods of Brahms's German Requiem.


In other religions like Christianity (like this song) or Hinduism (like this song), music (both lyrics and melody) is used to boost one's devotion to God, and could be uplifting too.

However, in Buddhism, this is against the seventh of the Eight Precepts:


  I undertake the precept to refrain from dancing, singing, music, going
  to see entertainments, wearing garlands, using perfumes, and
  beautifying the body with cosmetics.


The Gitassara Sutta (AN5.209) also states:


  There are, bhikkhus, these five drawbacks of reciting the Dhamma with
  a sustained melodic intonation. Which five? 
  
  Oneself gets attached to that intonation, others get attached to that
  intonation, householders get angry: 'Those ascetics who are followers
  of the Sakyans' son sing in the same way that we do!', there is a
  break in concentration for those striving [to produce] musicality, and
  the upcoming generations imitate what they see.
  
  These, bhikkhus, are the five drawbacks of reciting the Dhamma with a
  sustained melodic intonation.


Questions:


Is it ok to use music to induce positive states of mind, especially to uplift one's mood and alleviate depression?
If music can be used to uplift one's mood, then why is it considered unwholesome and against the seventh precept?
How does music cause attachment or craving?
Is it ok to use music to induce positive states of mind, especially to
  uplift one's mood and alleviate depression?


Yes, if you are a layman and if you are not observing the 8 precepts.


  If music can be used to uplift one's mood, then why is it considered
  unwholesome and against the seventh precept?


'Uplifting' here means inducing pleasurable thoughts/feelings. Even Marjuana can do that. Some people eat sweets to uplift themselves. Uplifting doesn't mean wholesome. It's important to note that hearing music by chance does not break the precept. Listening intently breaks the precept.


  How does music cause attachment or craving?


Music is sound that is pleasurable. Wanting to hear pleasurable sounds is a sign of craving.