Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from crewai import Agent, Task, Crew
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from udio_wrapper import UdioWrapper
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
+
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
| 10 |
+
udio_auth_token = os.getenv("UDIO_API_KEY")
|
| 11 |
+
udio_wrapper = UdioWrapper(udio_auth_token)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def run_agent(role, goal, backstory, task_description, expected_output):
|
| 15 |
+
# Create agent with user-specified parameters
|
| 16 |
+
general_agent = Agent(
|
| 17 |
+
role=role,
|
| 18 |
+
goal=goal,
|
| 19 |
+
backstory=backstory,
|
| 20 |
+
verbose=True,
|
| 21 |
+
allow_delegation=True
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Create task with user-specified parameters
|
| 25 |
+
task = Task(
|
| 26 |
+
description=task_description,
|
| 27 |
+
agent=general_agent,
|
| 28 |
+
expected_output=expected_output
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Create crew
|
| 32 |
+
crew = Crew(
|
| 33 |
+
agents=[general_agent],
|
| 34 |
+
tasks=[task],
|
| 35 |
+
verbose=2
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Execute crew kickoff
|
| 39 |
+
result = crew.kickoff()
|
| 40 |
+
song = make_song(task_description,result)
|
| 41 |
+
print(song)
|
| 42 |
+
song_path = song[0]['song_path']
|
| 43 |
+
|
| 44 |
+
return [result,song_path]
|
| 45 |
+
|
| 46 |
+
def make_song(task_description, result):
|
| 47 |
+
song = udio_wrapper.create_song(prompt=task_description,custom_lyrics=result)
|
| 48 |
+
return song
|
| 49 |
+
|
| 50 |
+
# Define Gradio interface
|
| 51 |
+
with gr.Blocks() as demo:
|
| 52 |
+
gr.Markdown("# Agent and Task Configuration")
|
| 53 |
+
|
| 54 |
+
role = gr.Textbox(label="Role of the Agent", placeholder="Enter the role of your agent")
|
| 55 |
+
goal = gr.Textbox(label="Goal of the Agent", placeholder="Enter the goal of your agent")
|
| 56 |
+
backstory = gr.Textbox(label="Backstory of the Agent", placeholder="Enter the backstory of your agent")
|
| 57 |
+
task_description = gr.Textbox(label="Task Description", placeholder="Enter the description of the task")
|
| 58 |
+
expected_output = gr.Textbox(label="Expected Output", placeholder="Enter the expected output of the task")
|
| 59 |
+
|
| 60 |
+
submit_button = gr.Button("Run Agent")
|
| 61 |
+
|
| 62 |
+
result = gr.Textbox(label="Result")
|
| 63 |
+
player = gr.Audio(label="Audio")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
submit_button.click(
|
| 68 |
+
fn=run_agent,
|
| 69 |
+
inputs=[role, goal, backstory, task_description, expected_output],
|
| 70 |
+
outputs=[result,player]
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# Launch the interface
|
| 76 |
+
demo.launch()
|