lets create a gradio app i can use to generate a song using suno docs and then be able to play the tracks, also if i wanted to make it a saas app specific to southafrica, give advice there too...
/v1/chat/completions: Generate music - Call the generate API in a format
that works with OpenAI’s API.
/api/custom_generate: Generate music (Custom Mode, support setting lyrics,
music style, title, etc.)
/api/generate_lyrics: Generate lyrics based on prompt
/api/get: Get music information based on the id. Use “,” to separate multiple
ids. If no IDs are provided, all music will be returned.
/api/get_limit: Get quota Info
/api/extend_audio: Extend audio length
/api/clip: Get clip information based on ID passed as query parameter id
/api/concat: Generate the whole song from extensions
Feel free to explore the detailed API parameters and conduct tests on this page.
Details of the API and testing it online
This is just a demo, bound to a test account. Please do not use it frequently, so that more people can test online.
suno-api
1.1.0
OAS 3.0
Use API to call the music generation service of Suno.ai and easily integrate it into agents like GPTs.
default
POST
/api/generate
Generate audio based on Prompt.
It will automatically fill in the lyrics.
2 audio files will be generated for each request, consuming a total of 10 credits.
wait_audio can be set to API mode:
• By default, it is set to false, which indicates the background mode. It will only return audio task information, and you will need to call the get API to retrieve detailed audio information.
• If set to true, it simulates synchronous mode. The API will wait for a maximum of 100s until the audio is generated, and will directly return the audio link and other information. Recommend using in GPTs and other agents.
Parameters
Try it out
No parameters
Request body
application/json
Example Value
Schema
{
"prompt": "A popular heavy metal song about war, sung by a deep-voiced male singer, slowly and melodiously. The lyrics depict the sorrow of people after the war.",
"make_instrumental": false,
"model": "chirp-v3-5|chirp-v3-0",
"wait_audio": false
}
Responses
Code Description Links
200
success
POST
/v1/chat/completions
Generate audio based on Prompt - OpenAI API format compatibility.
Convert the /api/generate API to be compatible with the OpenAI /v1/chat/completions API format.
Generally used in OpenAI compatible clients.
Parameters
Try it out
No parameters
Request body
application/json
Example Value
Schema
{
"prompt": "A popular heavy metal song about war, sung by a deep-voiced male singer, slowly and melodiously. The lyrics depict the sorrow of people after the war."
}
Responses
Code Description Links
200
success
Media type
application/json
Controls Accept header.
Example Value
Schema
{
"data": "string"
}
No links
POST
/api/custom_generate
Generate Audio - Custom Mode
The custom mode enables users to provide additional details about the music, such as music genre, lyrics, and more.
2 audio files will be generated for each request, consuming a total of 10 credits.
wait_audio can be set to API mode:
• By default, it is set to false, which indicates the background mode. It will only return audio task information, and you will need to call the get API to retrieve detailed audio information.
• If set to true, it simulates synchronous mode. The API will wait for a maximum of 100s until the audio is generated, and will directly return the audio link and other information. Recommend using in GPTs and other agents.
Parameters
Try it out
No parameters
Request body
application/json
Example Value
Schema
{
"prompt": "[Verse 1]\nCruel flames of war engulf this land\nBattlefields filled with death and dread\nInnocent souls in darkness, they rest\nMy heart trembles in this silent test\n\n[Verse 2]\nPeople weep for loved ones lost\nBattered bodies bear the cost\nSeeking peace and hope once known\nOur grief transforms to hearts of stone\n\n[Chorus]\nSilent battlegrounds, no birds' song\nShadows of war, where we don't belong\nMay flowers of peace bloom in this place\nLet's guard this precious dream with grace\n\n[Bridge]\nThrough the ashes, we will rise\nHand in hand, towards peaceful skies\nNo more sorrow, no more pain\nTogether, we'll break these chains\n\n[Chorus]\nSilent battlegrounds, no birds' song\nShadows of war, where we don't belong\nMay flowers of peace bloom in this place\nLet's guard this precious dream with grace\n\n[Outro]\nIn unity, our strength will grow\nA brighter future, we'll soon know\nFrom the ruins, hope will spring\nA new dawn, we'll together bring",
"tags": "pop metal male melancholic",
"title": "Silent Battlefield",
"make_instrumental": false,
"model": "chirp-v3-5|chirp-v3-0",
"wait_audio": false
}
Responses
Code Description Links
200
success
application/json
Example Value
Schema
{
"audio_id": "e76498dc-6ab4-4a10-a19f-8a095790e28d",
"prompt": "[lrc]Silent battlegrounds, no birds' song\nShadows of war, where we don't belong\nMay flowers of peace bloom in this place\nLet's guard this precious dream with grace\n[endlrc]",
"continue_at": "109.96",
"title": "",
"tags": "",
"model": "chirp-v3-5|chirp-v3-0"
}
POST
/api/generate_lyrics
Generate lyrics based on Prompt.
Generate lyrics based on Prompt.
Parameters
Try it out
No parameters
Request body
application/json
Example Value
Schema
{
"prompt": "A soothing lullaby"
}
Responses
Code Description Links
200
success
Media type
application/json
Controls Accept header.
Example Value
Schema
{
"text": "string",
"title": "string",
"status": "string"
}
No links
GET
/api/get
Get audio information
Parameters
Try it out
Name Description
ids
string
(query)
Audio IDs, separated by commas. Leave blank to return a list of all music.
application/json
Example Value
Schema
{
"error": "Missing parameter id"
}
No links
500
Internal server error
Media type
application/json
Example Value
Schema
{
"error": "Internal server error"
}
No links
POST
/api/concat
Generate the whole song from extensions.
Concatenate audio clips to generate a complete song using the provided clip ID.
Parameters
Try it out
No parameters
Request body
application/json
Example Value
Schema
{
"clip_id": "string"
}
Responses
Code Description Links
200
success
Media type
application/json
Controls Accept header.
Example Value
Schema
{
"id": "string",
"title": "string",
"image_url": "string",
"lyric": "string",
"audio_url": "string",
"video_url": "string",
"created_at": "string",
"model_name": "string",
"status": "string",
"gpt_description_prompt": "string",
"prompt": "string",
"type": "string",
"tags": "string"
}
No links
400
Clip id is required
Media type
application/json
Example Value
Schema
{
"error": "Clip id is required"
}
No links
402
Payment required
Media type
application/json
Example Value
Schema
{
"error": "Payment required"
}
No links
500
Internal server error
Media type
application/json
Example Value
Schema
{
"error": "Internal server error"
}
No links
Schemas
audio_info{
description:
Audio Info
id* string
audio id
title* string
music title
image_url* string
music cover image
lyric* string
music lyric
audio_url* string
music download url
video_url* string
Music video download link, can be used to share
created_at* string
Create time
model_name* string
suno model name, chirp-v3
status* string
The generated states include submitted, queue, streaming, complete.
gpt_description_prompt* string
Simple mode on user input prompt, Suno will generate formal prompts, lyrics, etc.
prompt* string
The final prompt for executing the generation task, customized by the user in custom mode, automatically generated by Suno in simple mode.
type* string
Type
tags* string
Music genre. User-provided in custom mode, automatically generated by Suno in simple mode.
}
Creating a Gradio application to generate and play songs using the Suno API is a fantastic idea! Additionally, transforming it into a SaaS (Software as a Service) platform tailored for South Africa involves several considerations, including localization, payment integration, and user management. Below, I’ll guide you through building the Gradio app and offer advice on scaling it into a South Africa-specific SaaS platform.
Part 1: Building the Gradio App
1. Setup and Requirements
First, ensure you have Python installed. You’ll also need to install the necessary libraries:
bash
pip install gradio requests
2. Understand Suno API Endpoints
Based on the provided documentation, the primary endpoints you’ll interact with are:
/api/generate: To generate audio based on a prompt.
/api/get: To retrieve generated audio information.
3. Gradio App Structure
Here's a step-by-step guide to building the Gradio app:
def create_song_interface(prompt, make_instrumental, model, wait_audio):
audio_link = generate_music(prompt, make_instrumental, model, wait_audio)
if audio_link.startswith("http"):
# Return the audio file so Gradio can play it
return gr.Audio.update(value=audio_link)
else:
# Return the error message
return audio_link
# Define Gradio Inputs
prompt_input = gr.Textbox(label="Song Prompt", lines=4, placeholder="Describe the song you want to generate...")
make_instrumental_input = gr.Checkbox(label="Instrumental Only", value=False)
model_input = gr.Dropdown(choices=["chirp-v3-5", "chirp-v3-0"], value="chirp-v3-5", label="Select Model")
wait_audio_input = gr.Checkbox(label="Wait for Audio (Synchronous)", value=False)
# Define Gradio Output
audio_output = gr.Audio(label="Generated Song")
# Create the Interface
interface = gr.Interface(
fn=create_song_interface,
inputs=[prompt_input, make_instrumental_input, model_input, wait_audio_input],
outputs=audio_output,
title="Suno AI Music Generator",
description="Generate and play your custom songs using Suno AI.",
theme="default"
)
# Launch the Interface
if __name__ == "__main__":
interface.launch()
f. Running the App
Save the above script as suno_gradio_app.py and run:
bash
python suno_gradio_app.py
This will launch a local Gradio interface where you can input prompts, customize options, and generate songs. The generated audio will be playable directly within the app.
4. Enhancements
Display Song Metadata: Fetch and display additional information like title, lyrics, and cover image.
python
def create_song_interface(prompt, make_instrumental, model, wait_audio):
audio_data = generate_music(prompt, make_instrumental, model, wait_audio)
if isinstance(audio_data, str) and audio_data.startswith("http"):
# Fetch audio info
audio_info = get_audio_info(ids=None) # Modify as needed
# Assume the first audio info is relevant
first_song = audio_info[0]["0"]
return {
"audio": gr.Audio.update(value=first_song["audio_url"]),
"title": first_song["title"],
"lyrics": first_song["lyric"],
"cover_image": first_song["image_url"]
}
else:
return audio_data
Multiple Audio Outputs: Allow users to generate multiple tracks at once.
Error Handling: Improve error messages and handle different response scenarios gracefully.
Part 2: Scaling to a South Africa-Specific SaaS Platform
Transitioning your Gradio app into a full-fledged SaaS platform tailored for South Africa involves several additional steps and considerations:
1. Localization
Language Support: South Africa has 11 official languages. Consider supporting multiple languages, especially English, Zulu, Xhosa, and Afrikaans, to cater to a broader audience.
Cultural Relevance: Ensure that the music styles, prompts, and generated content resonate with South African culture and preferences.
2. Payment Integration
Local Payment Gateways: Integrate with popular South African payment gateways like PayFast, PayGate, or Peach Payments to facilitate easy and secure transactions for your users.
Support Local Currencies: Ensure that pricing is in South African Rand (ZAR) to avoid currency conversion issues.
3. User Authentication and Management
User Accounts: Implement a robust user authentication system allowing users to create accounts, manage profiles, and access their generated content.
Subscription Plans: Offer various subscription tiers based on usage, features, and limits. For example:
Free Tier: Limited number of song generations per month.
Premium Tier: Unlimited generations, access to exclusive models, priority processing, etc.
4. Scalability and Hosting
Cloud Hosting: Use scalable cloud services like AWS, Google Cloud, or Azure to handle growing user bases and API requests.
CDN Integration: Utilize Content Delivery Networks (CDNs) like Cloudflare to ensure fast and reliable access to your service across South Africa.
5. Compliance and Security
Data Protection: Comply with South Africa’s Protection of Personal Information Act (POPIA) to protect user data.
Secure Transactions: Implement SSL/TLS encryption for all data transfers and secure payment processing.
6. Marketing and Support
Targeted Marketing: Use digital marketing strategies focusing on South African platforms and communities. Collaborate with local influencers and music artists to promote your service.
Customer Support: Provide timely and effective customer support, preferably in local languages, to assist users with issues and queries.
7. Feature Enhancements for SaaS
User Dashboards: Develop comprehensive dashboards where users can manage their generated songs, view usage statistics, and handle billing.
API Access: Offer API access for advanced users or businesses wanting to integrate music generation into their own applications.
Analytics: Provide analytics on song generations, popular genres, and user preferences to help refine your service.
8. Legal Considerations
Terms of Service and Privacy Policy: Clearly outline your service’s terms, user rights, and data handling practices.
Copyright and Licensing: Ensure that generated music complies with copyright laws and consider offering licensing options for commercial use.
Part 3: Example SaaS Tech Stack
To build a scalable SaaS platform, consider the following technology stack:
Frontend:
Frameworks: React.js, Vue.js, or Angular for dynamic user interfaces.
Styling: Tailwind CSS or Bootstrap for responsive design.
Backend:
Frameworks: Django or Flask for Python-based applications, or Node.js with Express.
Database: PostgreSQL or MongoDB for storing user data and metadata.
Authentication: Implement OAuth 2.0 or JWT for secure user authentication.
Cloud Services:
Hosting: AWS (EC2, S3), Google Cloud Platform, or Azure.
CI/CD: GitHub Actions, GitLab CI, or Jenkins for continuous integration and deployment.
Payments:
Integration: PayFast API or other local payment gateway APIs.
Email Services:
Providers: SendGrid, Mailgun, or Amazon SES for transactional and marketing emails.
Part 4: Additional Tips
User Feedback: Continuously gather and incorporate user feedback to improve your service features and user experience.
Performance Optimization: Monitor and optimize the performance of your app to handle high traffic and ensure fast response times.
Documentation: Provide comprehensive documentation and tutorials to help users make the most of your platform.
Partnerships: Collaborate with local artists, music producers, and educational institutions to expand your reach and credibility.
Conclusion
Building a Gradio app to interact with the Suno API is a great starting point. By following the steps outlined above, you can create a functional app that generates and plays music. Scaling it into a South Africa-specific SaaS platform involves additional layers of complexity, including localization, secure payment integration, user management, and compliance with local laws. With careful planning and execution, you can create a successful and impactful service tailored to the South African market.
If you have specific questions or need further assistance with any part of the process, feel free to ask!