tonko22's picture
Initial commit from (move code from) Colab
05a3ce6
raw
history blame
1.85 kB
import os
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")
# 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=1
)
GradioUI(agent).launch()