File size: 2,165 Bytes
f2a89b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from crewai import Agent, Task, Crew
import os
from dotenv import load_dotenv
from udio_wrapper import UdioWrapper

# Load environment variables
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
udio_auth_token = os.getenv("UDIO_API_KEY")
udio_wrapper = UdioWrapper(udio_auth_token)


def run_agent(role, goal, backstory, task_description, expected_output):
    # Create agent with user-specified parameters
    general_agent = Agent(
        role=role,
        goal=goal,
        backstory=backstory,
        verbose=True,
        allow_delegation=True
    )

    # Create task with user-specified parameters
    task = Task(
        description=task_description,
        agent=general_agent,
        expected_output=expected_output
    )

    # Create crew
    crew = Crew(
        agents=[general_agent],
        tasks=[task],
        verbose=2
    )

    # Execute crew kickoff
    result = crew.kickoff()
    song = make_song(task_description,result)
    print(song)
    song_path = song[0]['song_path']

    return [result,song_path]

def make_song(task_description, result):
    song = udio_wrapper.create_song(prompt=task_description,custom_lyrics=result)
    return song

# Define Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Agent and Task Configuration")

    role = gr.Textbox(label="Role of the Agent", placeholder="Enter the role of your agent")
    goal = gr.Textbox(label="Goal of the Agent", placeholder="Enter the goal of your agent")
    backstory = gr.Textbox(label="Backstory of the Agent", placeholder="Enter the backstory of your agent")
    task_description = gr.Textbox(label="Task Description", placeholder="Enter the description of the task")
    expected_output = gr.Textbox(label="Expected Output", placeholder="Enter the expected output of the task")

    submit_button = gr.Button("Run Agent")

    result = gr.Textbox(label="Result")
    player = gr.Audio(label="Audio")



    submit_button.click(
        fn=run_agent,
        inputs=[role, goal, backstory, task_description, expected_output],
        outputs=[result,player]
    )



# Launch the interface
demo.launch()