What’s better than having AI write your code?
A big problem with AI writing code is that neophytes like me (CS was my undergrad, but I never really used it, alas) don’t know good code versus bad code unless VS Code gives me the little squiggly underline thing telling me my code won’t work (insert IG reel with “it’s got no gas”).
So, along comes AI, and we get co-pilot and the Amazon thing I can’t remember the name of, and then each day (it seems), we have another LLM model that can effectively write code. And so it goes day after day. What a time to be alive!
But, the other day, I ran across something that takes this idea to the next level. Instead of writing code and having AI write it for you only to review it for accuracy, how about fully trusting the AI to write it and never even looking at it? Enter Marvin. This framework (akin to Langchain, if you are familiar with it) provides a couple of ways of seamlessly using AI in your apps (aka super easy). They describe it as “batteries included,” meaning it has everything you need to use it and does not depend on further external libraries. This is the same concept as Django, which, if you haven’t explored it, is a quick and efficient way to set up a website.
Check out the quickstart on AskMarvin.AI, they outline three scenarios. I played with the first and the 3rd and wanted to highlight the 3rd one here in this post, as I think it’s the coolest.
Here is my code. I will make a few comments about it below.
import os import streamlit as st from dotenv import load_dotenv from youtube_transcript_api import YouTubeTranscriptApi from marvin import ai_fn load_dotenv() # marvin.settings.openai_api_key = os.getenv("OPENAI_API_KEY") @ai_fn def summarize_video(text: str) -> str: """ Given `text` which is a transcript from a YouTube video, returns a summary of the video. """ st.title("Summarize a YouTube Video") st.divider() # Getting input from the user and displaying activity with st.form("Input_Form", clear_on_submit=True): video_url = st.text_input( "Enter the URL for the YouTube Video (Note: grab the URL from the browser URL bar, not the YouTube share URL):" ) submitted = st.form_submit_button("Submit") if submitted: video_id = video_url.split("watch?v=")[-1] st.info("Fetching transcript...") # Transcribing the video transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=["en"]) transcript_text = " ".join([entry["text"] for entry in transcript]) st.info("Summarizing...") summary = summarize_video(transcript_text) # Displaying the summary st.write("Summary of the video:" + summary) video_url = st.empty()
Check out the function called summarize_video
. Notice there is no real code in there, just comments. Based on the comments, AskMarvin interprets what that function should do. This is very similar to how GitHub’s co-pilot functions. You provide the comments, and it will attempt to write the function for you. But this is better because you only need to provide the comments, and the framework handles the heavy lifting.
Very simply, the “app” grabs the video ID provided by the YouTube Video URL (if you use my code, the video has to be short, like < 9min), grabs the transcript, and then uses OpenAI to summarize the transcript. If I wanted to have it provide more than just a summary, change the comments in the function, and voila.
Enjoy!