Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,16 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Web search tool to find trending music
|
| 11 |
search_tool = DuckDuckGoSearchTool()
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
# Custom tool for AI-assisted music generation
|
| 14 |
@tool
|
| 15 |
def generate_music(theme: str) -> str:
|
|
@@ -17,13 +21,19 @@ def generate_music(theme: str) -> str:
|
|
| 17 |
Args:
|
| 18 |
theme: The theme or mood of the music (e.g., 'moody jazz on a rainy night').
|
| 19 |
"""
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Tool to generate an album cover
|
| 29 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from transformers import pipeline
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Web search tool to find trending music
|
| 12 |
search_tool = DuckDuckGoSearchTool()
|
| 13 |
|
| 14 |
+
# Load the MusicGen model
|
| 15 |
+
pipe = pipeline("text-to-audio", model="facebook/musicgen-large")
|
| 16 |
+
|
| 17 |
# Custom tool for AI-assisted music generation
|
| 18 |
@tool
|
| 19 |
def generate_music(theme: str) -> str:
|
|
|
|
| 21 |
Args:
|
| 22 |
theme: The theme or mood of the music (e.g., 'moody jazz on a rainy night').
|
| 23 |
"""
|
| 24 |
+
try:
|
| 25 |
+
# Generate music using the pipeline
|
| 26 |
+
output = pipe(theme)
|
| 27 |
+
|
| 28 |
+
# Extract the generated audio file
|
| 29 |
+
audio_url = output[0]["audio"] if "audio" in output[0] else None
|
| 30 |
+
|
| 31 |
+
if audio_url:
|
| 32 |
+
return f"Here’s your AI-generated music for '{theme}': {audio_url}"
|
| 33 |
+
else:
|
| 34 |
+
return "Music generation failed. Try a different theme!"
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error generating music: {str(e)}"
|
| 37 |
|
| 38 |
# Tool to generate an album cover
|
| 39 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|