File size: 2,176 Bytes
05a3ce6
0f4f8b4
05a3ce6
 
 
 
 
 
 
 
 
 
de58e79
05a3ce6
de58e79
05a3ce6
 
 
 
 
 
 
 
 
 
 
 
 
de58e79
05a3ce6
 
 
 
de58e79
05a3ce6
 
 
de58e79
05a3ce6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de58e79
05a3ce6
 
0f4f8b4
 
de58e79
05a3ce6
 
 
 
 
 
 
 
 
 
 
cb31ce4
0f4f8b4
 
 
de58e79
 
0f4f8b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import yaml
from Gradio_UI import GradioUI
from litellm import completion
from smolagents import (
    CodeAgent,
    DuckDuckGoSearchTool,
    FinalAnswerTool,
    LiteLLMModel,
    VisitWebpageTool,
    tool,
)

os.environ["GEMINI_API_KEY"] = os.getenv("GEMINI_API_KEY")

@tool
def analyze_lyrics_tool(song_title: str, artist: str, lyrics: str) -> str:
    """
    Performs a deep analysis of the musical track, given its metadata.
    
    Args:
        song_title: title of the song or music trach.
        artist: The name of the artist.
        lyrics: The lyrics of the song.
    
    Returns:
        A summary of the song's meaning in English.
    """

    prompt = f'''You are an expert in songs and their meanings. 
    Summarize the meaning of {song_title} by {artist} and identify 
    key themes based on the lyrics: 
    {lyrics}. 

    Includs deep idea and vibes analysis with explainations 
    based on references to the exact lines
    '''

    response = completion(
        model="gemini/gemini-2.0-flash", 
        messages=[
            {"role": "user", "content": prompt}
            ])
    
    try:
        lyrics = response.choices[0].message.content.strip()
        return lyrics
    except (AttributeError, KeyError, IndexError):
        try:
            lyrics = response['choices'][0]['message']['content'].strip()
            return lyrics
        except (AttributeError, KeyError, IndexError):
            pass

final_answer = FinalAnswerTool()
model = LiteLLMModel(model_id="gemini/gemini-2.0-flash")
with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)

# Example usage within the agent
agent = CodeAgent(
    tools=[
      FinalAnswerTool(), 
      DuckDuckGoSearchTool(),
      VisitWebpageTool(),
      analyze_lyrics_tool
    ], 
    model=model,
    additional_authorized_imports=['numpy', 'bs4'],
    max_steps=22,
    verbosity_level=0,
    name="Song Lyrics Analyzer",
    description="Analyze the meaning of song lyrics and identify key themes based on the lyrics using web search tools and deep lyrics analysis tool.",
    prompt_templates=prompt_templates
)

GradioUI(agent).launch()