Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a bot to create a song from text #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions examples/riffusion-bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from textbase import bot, Message
from textbase.models import RiffusionAI # Import your RiffusionAI class
from typing import List

RiffusionAI.api_key = ""

SYSTEM_PROMPT = """You are chatting with an AI. There are no specific prefixes for responses, so you can ask or talk about anything you like.
The AI will respond in a natural, conversational manner. Feel free to start listeneing music of your lyrics.
"""

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate audio response based on user_message
audio_url = RiffusionAI.generate(
system_prompt=SYSTEM_PROMPT,
message_history=message_history # Assuming history is the list of user messages
)

response = {
"data": {
"messages": [
{
"data_type": "AUDIO",
"value": audio_url
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
33 changes: 32 additions & 1 deletion textbase/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,35 @@ def generate(
data = json.loads(response.text) # parse the JSON data into a dictionary
message = data['message']

return message
return message

class RiffusionAI:
api_key = None

@classmethod
def generate(
cls,
system_prompt: str,
message_history: list[Message],
user_input
):
# Define input parameters for the model
input_params = {
"prompt_a": user_input,
"denoising": 0.75,
"prompt_b": "", # Leave blank if no interpolation
"alpha": 0.5,
"num_inference_steps": 50,
"seed_image_id": "vibes" # Choose a seed spectrogram from allowed values
}

# Specify the model URL
model_url = "riffusion/riffusion:8cf61ea6c56afd61d8f5b9ffd14d7c216c0a93844ce2d82ac1c9ecc9c7f24e05"

# Run the model
output = replicate.run(model_url, input=input_params)

# Access the generated audio URL
audio_url = output["audio"]

return audio_url