File size: 1,749 Bytes
9b5b26a
 
 
 
c19d193
6aae614
8fe992b
9b5b26a
 
fe11f80
 
9b5b26a
fe11f80
9b5b26a
fe11f80
 
9b5b26a
fe11f80
9b5b26a
fe11f80
 
 
 
 
 
 
 
 
 
ae7a494
fe11f80
 
 
ae7a494
fe11f80
e121372
fe11f80
 
 
 
13d500a
8c01ffb
fe11f80
 
8c01ffb
8fe992b
fe11f80
8c01ffb
 
 
 
fe11f80
 
861422e
8fe992b
 
9b5b26a
fe11f80
 
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
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool

from Gradio_UI import GradioUI

# Web search tool to find trending music
search_tool = DuckDuckGoSearchTool()

# Custom tool for AI-assisted music generation
@tool
def generate_music(theme: str) -> str:
    """Generates an AI-assisted music piece based on the given theme.
    Args:
        theme: The theme or mood of the music (e.g., 'moody jazz on a rainy night').
    """
    response = requests.post(
        "https://huggingface.co/api/text-to-music", 
        json={"prompt": theme}
    )
    if response.status_code == 200:
        return f"Here’s your AI-generated music for '{theme}': {response.json().get('music_url', 'Music not available')}"
    return "Failed to generate music. Try another theme!"
    
# Tool to generate an album cover
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)

# Load prompts
with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)

# Define model
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
    custom_role_conversions=None,
)

# Initialize agent
final_answer = FinalAnswerTool()
agent = CodeAgent(
    model=model,
    tools=[final_answer, search_tool, generate_music, image_generation_tool],
    max_steps=6,
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name="Music Inspiration Agent",
    description="An agent that generates music and album covers based on user themes.",
    prompt_templates=prompt_templates
)


# Launch UI
GradioUI(agent).launch()