Build An Audio AI App Transcripts
Chapter: Feature 3: Summarize
Lecture: Do We Have a Summary Already?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that we have the whole UI interaction working perfectly, all that's left is, well, you know,
0:07 to use AI like magic to summarize and pull out key moments from an hour long of audio. So let's do that with Assembly AI now, huh?
0:18 All right, so here's what happens when we say start job. And remember, it just started and immediately said,
0:23 it's done because there was no actual work to do. If we're gonna navigate over to this create job here, and that's in this background service,
0:32 and it starts the job, we gotta scroll down a little bit into this timer piece that goes around and says, which one, which action was it?
0:40 It's summarized, so we're gonna go over here. And I've sketched out a couple of things that I want to do in blocks.
0:47 Oh, I don't overwhelm you with just doing a whole bunch of stuff, 'cause this will take a few minutes. So the first question we need to ask here is,
0:55 do we already have everything that we need? And how does that work? Well, maybe we've already, just like the transcripts, summarized this,
1:04 and we don't want to send it over to Assembly AI again. Remember, that costs credits or money, and it's also just slow compared to the one millisecond
1:14 it takes to return it from the database. So anytime you've already done the work, just don't do the work again if you can.
1:20 And the way we're gonna do that, we'll say db transcript. Just like before in the transcribed section, it's real similar.
1:28 We're just gonna go to the database and get it. So we'll say full transcript for episode, and we're passing in the podcast ID and the episode number,
1:36 and PyCharm automatically created, auto-completed all the parameters. Very nice, PyCharm. But again, this is asynchronous
1:44 because it talks to the database, so we've got to await it. Now, unlike before, having the transcript is not enough.
1:51 We also have to have the transcript plus the summary, and it's stored on the transcript. So we can say if db transcript and db transcript.summary,
2:00 you see there's a summary TLDR and bullets. It doesn't matter which one we look for. You can see they're both either a string or none.
2:11 Just checking one should be enough. So if we already have some kind of summary, you know what, we're good to go. We'll just return db transcript.
2:18 The worker doesn't use this, but it might be useful somewhere else. For example, in case something could use the return value,
2:24 we'll go ahead and return it. But most importantly, we just don't do the work. We'll just tell the job, hey, you know what job, you're done.
2:31 Kind of like it's already been doing. Also, there's another situation where we have no transcript whatsoever.
2:39 So if you look at the UI, there was the make a transcript, and then another create the summary button. So they could create the summary
2:47 even before the transcript existed. And we could either say, well, first you have to click the transcript button, wait,
2:53 and then click the summary button later. But why don't we just go ahead and make one for them? So if there's no transcript whatsoever,
3:00 we can say db transcript equals, and we just scroll up here. This is the other worker function, worker transcribe episode.
3:09 Okay, that was being used automatically, but let's go ahead and just reuse this here. We'll await worker transcribe episode.
3:16 PyCharm, are you going to do it for us? Not this time. Oh, maybe it would. It tried. So now this is definitely going to work.
3:24 We're going to have our database transcript, but it still won't have the summary information, right?
3:30 So at least let's go ahead and put something like this. If not db transcript, we'll do this, it won't print out. There we go.
3:40 If there's no transcript yet, we're going to go ahead and make one, and then we're going to summarize it. So if you click the create summary button
3:47 and there's no transcript, sure, it'll take a little bit longer, but what's the alternative? Make them click two buttons over long periods of time.
3:54 So we're just going to go ahead and do it like this. I think that's a decent start. So step one, if we have what we need, just give it back.
4:01 If not, we're going to need the transcript because the way this works is we're going to send the transcript text over to Lemur
4:08 and ask it to summarize it, not the audio directly.


Talk Python's Mastodon Michael Kennedy's Mastodon