How to build a text to Google slide using GPT-3 in under an hour.
Just describe your details and get a slide generated
From my previous experiments on GPT-3 I had shown how GPT-3 was really good at identifying patterns and filling slots. I had even shown a demo of text to slide generator. In this post I will walk you through the exact steps I followed and recreate the steps in real time to show you how I built the demo. Hopefully this will also help people understand how I build mashups and maybe will help them also to build their own mashups. Actual prompts used and the code used given below.
11:00 AM - Idea, let’s build a text to Google slide generator. But how. Lets come up with a pipeline.
Brain starts working thinking of different pipelines.
11:10 AM - I finally settle on Text-Json-Google slide format.
We will use GPT-3 for text to json. Time to check out different examples on OpenAI playground and see which one fits us the best.
11:20 AM - I decide on the Parse unstructured data template. So I guess we can take unstructured data and generate structured json from this.
So I adapted the content from this template and created a json format. I decided the json format will have a title and list elements. Then I tried out a simple statement using the Q&A template as it has start and stop sequences. And voila, it worked on the first attempt itself.
11:30 AM - I take this and expose this as a simple REST API. Nothing special, just a basic flask service on top of the python code I have and I expose this to public using ngrok.
Nice. Now for the json to Google slide code. We will obviously need Google slide scripting. But I have no clue how that works. So onto Google:
So I go to the first link(https://developers.google.com/apps-script/guides/slides) and quickly scan it to see that there is a sample add on https://developers.google.com/gsuite/add-ons/editors/slides/quickstart/translate. I decide to adapt this.
11:45 AM - From the quick start template I follow the steps provided.
I quickly scan the code and find the below:
So, I have the text and instead of calling translate function I can just replace that with my API call.
11:50 AM - I do that and I have the converted text in the slide.
But I have to format it. Change the Title to a heading. And add individual text elements in the slide. And I have no clue about Google slide programming :(. Back to Google.
The first link gives me this, https://developers.google.com/apps-script/guides/slides/editing-styling
It is at this moment that I realize I will not be able to maintain the timeline I kept for myself. No way in hell can I understand all that structure and finish coding in an hour :(. Damn.
Well, to be fair, which software project has been completed on time :)
12:30 PM - So, after going through the styling link, I realize I have to work with the TEXT_BOX shape(https://developers.google.com/apps-script/guides/slides/editing-styling#text_styling)
So I copy paste the below code and change the text to the text returned by the API.
Great! This works.
12:45 PM - I just loop through the json elements and add text boxes to the slide. The final script code can be found in this gist. As you can see its just the translate add on code with code from styling text box code.
1:00 PM - And we are done. So thanks to OpenAI, Google and some good copy pasting skills we are able to build a quick text to slide generator in a couple of hours.
You can find a demo here:
Appendix:
The actual prompt I used for priming GPT-3 is below. For parameters I used the default Q&A playground parameters.
Prompt:
Q: There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy. There are also loheckles, which are a grayish blue fruit and are very tart, a little bit like a lemon. Pounits are a bright green color and are more savory than sweet. There are also plenty of loopnovas which are a neon pink flavor and taste like cotton candy. Finally, there are fruits called glowls, which have a very sour and bitter taste which is acidic and caustic, and a pale orange tinge to them.
A: {"title":"Fruits on Goocrux","elements":["Neoskizzles-Purple, taste like candy.","Loheckles-Grayish blue fruit. Very tart and a little bit like lemon","Pounits-Bright green color. More savory than sweet.","Loopnovas-Neon pink flavor. Taste like cotton candy","Glowls-Pale orange tinge. Very sour and bitter taste which is acidic and caustic."]}
Q: Ozonetel has many teams. The sales team has 120 people. The support team has 40 people. The development team has 40 people.