keivalya commited on
Commit
1dd989d
·
verified ·
1 Parent(s): 1e546b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -11,23 +11,21 @@ from groq import Groq
11
  # Load environment variables from .env file
12
  # load_dotenv()
13
 
14
- client = Groq(
15
- api_key="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",
16
- )
17
-
18
  def song_history(message):
19
  question = "Tell me the history or a fun fact of the song (in a single line!): " + message
20
  completion = client.chat.completions.create(
21
  model="llama3-8b-8192",
22
- messages=[question],
 
 
 
23
  temperature=1,
24
  max_completion_tokens=1024,
25
  top_p=1,
26
  stream=True,
27
  stop=None,
28
  )
29
- for chunk in completion:
30
- return chunk.choices[0].delta.content or ""
31
 
32
  def analyze_song(mp3_file):
33
  # Call the transcription function and get the transcription
@@ -61,8 +59,8 @@ def analyze_song(mp3_file):
61
  instrumentation = "Sample Instrumentation"
62
  lyrics = transcription # Use the transcription as lyrics
63
  tempo_key = "Sample Tempo/Key"
64
- history = "History"
65
- history = song_history(title)
66
  return title, artist, genre, instrumentation, lyrics, tempo_key, history, image_url # Return the mp3 file for replay
67
 
68
  # Custom CSS to set a fun musical theme image as background
 
11
  # Load environment variables from .env file
12
  # load_dotenv()
13
 
 
 
 
 
14
  def song_history(message):
15
  question = "Tell me the history or a fun fact of the song (in a single line!): " + message
16
  completion = client.chat.completions.create(
17
  model="llama3-8b-8192",
18
+ messages=[
19
+ SystemMessage(content="You are a professor of music at Berklee College of Music. Your students are asking you questions about the historical context and musical significance of songs they listened to. Please structure the output as a json with the format {'historical': historical significance of song, 'musical': special musical characteristics of the song, 'instrumentation': [instrument 1, instrument 2, ...], 'tempo': tempo of the song, 'key': key of the song}, 'genre': genre of the song"),
20
+ UserMessage(content="Please explain the historical and musical significance of " + message + ". Please also break down the instruments used in the song."),
21
+ ],
22
  temperature=1,
23
  max_completion_tokens=1024,
24
  top_p=1,
25
  stream=True,
26
  stop=None,
27
  )
28
+ return completion.choices[0].message.content
 
29
 
30
  def analyze_song(mp3_file):
31
  # Call the transcription function and get the transcription
 
59
  instrumentation = "Sample Instrumentation"
60
  lyrics = transcription # Use the transcription as lyrics
61
  tempo_key = "Sample Tempo/Key"
62
+ # history = "History"
63
+ history = "song_history(title)"
64
  return title, artist, genre, instrumentation, lyrics, tempo_key, history, image_url # Return the mp3 file for replay
65
 
66
  # Custom CSS to set a fun musical theme image as background