FreestyleGPT: An AI Chat App that Generates Rap Lyrics

Logan Norman
Geek Culture
Published in
6 min readFeb 27, 2023
if you know, you know

⬇️ ️️a demo of the app can be found below ⬇️

Introduction

When the beat drops and the words start to flow, freestyle rap transforms into a raw, unfiltered form of artistic expression that captivates both the artist and the audience. Freestyle is a style of improvisation, with or without instrumental beats, in which lyrics, aka bars, are recited with no particular subject or structure and without prior memorization.

I’ve always enjoyed listening to the eccentric flows, creative rhymes, and, most of all, jaw-dropping punch lines in freestyle rap. The art form allows for a range of emotions, from lighthearted humor to political commentary, and allows individuals to express themselves uniquely and powerfully. Freestyle rap has become a significant part of contemporary hip-hop culture and has been used as a tool for self-expression, community building, and activism. It encourages artists to tap into their creative potential, break down barriers, and push the boundaries of what is possible in music.

Freestyle rap requires quick thinking, clever wordplay, and an ability to connect ideas seamlessly in a way that resonates with the listener; however, are these skills only a human can master? With the rapid development in the world of natural language processing and text generation, I decided to put this question to the test:

Is there an AI that can freestyle with me bar for bar ❓❓❓

3am Thoughts

The way that a freestyle typically goes is that after one bar is given, another is given based on the former. For example,

Bar 1: I don’t understand why people like eating crepes

Bar 2: I’m surprised that some doctors did surgery on a grape

The above format works for individuals doing a freestyle solo or in a group of friends. With the nature of freestyle in mind, a chat app that generates the next bar would be the ideal format for a freestyling AI.

Regarding how the lyrics would be generated, I looked to the hottest thing on the block right now: ChatGPT. I knew that ChatGPT could write songs and poems, so I assumed it could also write the next bar in a freestyle. It probably can, but the ChatGPT API is not yet available, so I got the next best thing: OpenAI’s latest GPT3 model, Davinci3. Per the documentation, this model is the “most capable GPT-3 model. Can do any task the other models can do, often with higher quality, longer output and better instruction-following. Also supports inserting completions within text.” Since this model supports text completion and instruction following, I decided to use it to impute the next bar.

After I had the format and how to generate the next bar, I needed to pick a medium for the user to interact with the model. I’d been meaning to get into iOS development for a few months, so I decided to use this app as my intro. By having a mobile app, the app's usability significantly increases and allows anyone to have a smooth and well-designed platform to have a freestyle session. I considered building a web app for this project but wanted to prioritize the mobile version first because iOS was more interesting to me. My aim was to simulate the experience I had freestyling late at night in my friend’s car to classic hip-hop beats.

Development

The blueprint I created from my 3am thoughts threw me in the right direction of knowing what I needed to learn. I knew I needed to do two things:

  1. Learn how to use GPT3 to generate the next bar 🎼
  2. Learn how to build an iOS app 📱

One of those tasks was much more complex than the other.

Getting the next bar

Let’s start with the first of the two steps. OpenAI has a nice playground to mess around with different parameters and inputs to the model to see the resulting output.

example of openai’s playground

I toyed around with this for a little bit and got solid results. This is the prompt I ended up using to get the desired output for the app:

api prompt

I could generate a bar from any text by inputting the above prompt and tuning some of the available parameters to the API; however, this doesn’t mean the bar was always good.

I had trouble with the model returning a response that didn’t rhyme with the input, went completely off-topic, took too long to generate, made no sense in context, or repeated the rhyming word from the input. These issues are partially due to the current state of GPT3, but with the help of some parameter tuning and prompt engineering, I avoided them for the most part.

Learning iOS Dev

Coming into this project, I had zero experience in iOS development. This past summer, though, I did an internship focused on Android development, so I postulated that iOS and Android development would be similar. I’m very much a project-based learner, so I looked up Youtube videos about how to build basic apps in iOS. Upon this initial search, I realized there’s somewhat of a split in the iOS dev community about using SwiftUI or UIKit. SwiftUI is a newer framework that seemed easier to whip up an app with while UIKit is older.

I dabbled in UIKit through CodePath’s iOS course. It was decent and quite similar to Android, which I liked. Then I checked out SwiftUI through different Youtube tutorials. I found that SwiftUI was much easier for me to build nice UIs with and had fewer steps than UIKit, so in the interest of time, I decided to go with SwiftUI.

Once I picked up the basics of SwiftUI, I postulated what I needed to do to build this app. Basically, the app is a chat app between the user and an API. So, I needed to learn how to build a chat app and how to hit an API in Swift. To do this, I followed a tutorial about doing a similar task. This tutorial taught me the bare bones of what I needed to do. Then, I decided to put my own spin on the app. I did this by completely revamping the UI, changing the functionality of the app, switching up some API parameters, and adding more functionality to the app, such as the ability to play the freestyle created and clear current messages along with many other minor changes to make the app my own. Shoutout to my friends that gave me suggestions on how to improve💰.

FreestyleGPT

I stayed up until 6am one night to build the entire project. Then, I spent a few hours the following weekend adding the finishing touches to the app. Here’s the demo:

demo of the application

This app accomplished the purpose of being a freestyle buddy at any time that anyone can use. I finally got to work in iOS development and look forward to creating more apps in the future. I also got to try out GPT3 in a different context than I had before.

What do you think about the app? How do you think it should be improved?

Wrap Up

I enjoyed building out this app from scratch and learning two new technologies. The future of AI is looking bright, and I’d like to harness it to make more exciting apps.

If you enjoyed reading about this project, follow me on Medium. I write about my journey building projects like this one, such as predicting sneaker prices, generating conspiracy theories, or a spotify song recommendation system.

What are your thoughts on this project? Let me know in the comments.

Feel free to reach out on LinkedIn and follow my work on GitHub. You can also see what I’m up to on my Twitter. All code for this project can be found on the GitHub here.

I appreciate you taking the time to check out my work, and I hope you enjoyed it. I pray you are well and many blessings come your way!

Logan

--

--