Article/Blog Generation App using Llama2, Langchain, and Pexels

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to AI anytime Channel in today's video we are going to work on a simple but a very interesting project okay so we are going to use lava 2 and pixels to create a an article generator app where where the end user will you know submit an idea or topic and then we'll utilize a large language model gamma 2 in this case you know to generate some content and then we'll use pixels you know to fetch an image related to that topic or idea and then we'll combine it together and and we'll generate an article in a docx or DOC format okay now the end user can download that document which is in DOC format and you know he or she can edit that if required and use it for whatever purpose they want to use so we're going to build this simple app in streamlit where you just submit an idea a topic and the app will basically give you an option to download the entire article okay on top of it that's what we are going to build in this video so if you see on my screen you know I have something called article generator app using llama2 that's what we are going to build so for example if you see please enter the idea topic for the article you want to generate so I've given the input here called sustainable future and please enter the topic for the image you want to face so we can also give these options where the user can you know put the idea or uh the topic for the image as well most of the time what happens you will you will look for a similar kind of an image like let's do sustainable future but sometimes you can also have an option to give an image of a girl or a boy or you know something which might not be related but can be used as a storytelling right a person having a laptop in his hand where you know you have some uh carbon footprint or something like that right so it's better to have both the options for Content you have a separate option and for image you have a separate input box so this is what we are going and for example when we said green world you can see the image that we have first faced so we have a fist and image okay from pixels so pixels is a stock image provider okay when they provide different type of stock images videos Etc now you can also use unsplash pixabay restock etc etc and Depends you know what what you want to use I have used pixels because it's easy to use I'll show you that how you can leverage pixels uh to basically fetch an image and you can see generated content by llama2 uh user input sustainable future and the text title a sustainable future why it matters and how we can achieve it that's that's the title of your article now you can if you want to post on Instagram or LinkedIn or on your website if you are working as a digital marketer or or SEO expert or something right where you or even as a marketing guy or a content creator you want to you know post something based on sustainable future then at least you can generate some content you know you can see the content that I have generated using llama2 the world we live in today is facing numerous challenges that threaten the very survival of our planet climate change deforestations etc etc so it's a good uh content that we have generated and we'll write some prompt and in that process of writing the prompt I will also show you that how we can also you know generate better content now if we have an structure where you want to you know basically follow in your article or blog that you write for example you start with some introduction then you go in the body or methodology or description then you end with a conclusion or something you can also set that in the prompts you can also design your prompt in a way to generate the content accordingly right so I'm going to have a a very simpler problem but I will explain that how you can modify that as well so we have three column here on the streamlit application in the First Column we have generated contained by llama2 in the second column I have something fixed image and the third column I have final article to download so you can also download the word document because you would like to edit it something right before posting it or sharing it with somebody I'll show you the generated content this is a dock that we have created you can see over here see it over here we have something called sustainable future this was the idea of topic that I have submitted here on the estimated application and then I have a title and then I have some you know body text or description some article on that you can see the this can be done by transitioning to renewable energy sources such as solar and wind power Etc and then we're talking about you know also require addressing social and economic inequalities Etc so very good content writer that I that I'm seeing right now so we have used Lama 2 to generate this and then we have a title and then we have an image that we have faced you know from uh pixel so this is a separate document that I have shown earlier when I was testing it I have tested different you know multiple times you can see the image which which we have faced using pixels this comes from llama 2 and then we have this in this doc file now you can also edit it and design it the way you want for example you know we should all follow this would all follow sustainable practices or something okay something like this okay and now you can just save it and you know save somebody over an email or somebody you know at your workplace or wherever you want to you will basically right you can you can use that you can see the way you can also make it smaller sort of something okay so this is what we are going to you know develop in this video guys I'll just save this for now so you can see this is how the interface looks like the HTML interface so for this we need few things we need lamba 2 uh the model also I have couple of videos on llama I'll give the link in the description uh we're gonna use llama two we're gonna use pixels we're gonna use it equest and you can also use couple of other libraries and dependencies that I will show you so let's let's build this guys let me open my project folder and now go inside uh whatever two and let me just go back let me rename this guy I don't know why I rename PPD llama too because I was working on an app uh so that app we're gonna create PPT using lava 2 and python but I'm going to write this article or something okay I'm gonna do article and I'm going to open this in vs code Okay so let me just open that in es code and okay so if you see I already have downloaded the file uh the model file of llama 2. if you want to download same model file you know you can also download uh model files I can show you maybe you can go to meta AI llama to HF hugging face and you can take any of this meta Lama model if you have a GPU machine it might not probably work on a CPU and you can see all the GPU based models can find it over here all the original meta llama model llama 2. now if you don't have a GPU machine then you have to go to block uh comma 2 HF so we have to go to block llama2 and you can look at all the models that block has created as a quantized model compression techniques uh the compression techniques are amazing like because it helps you run llms on commodity Hardwares like a single consumer GPU or a good CPU machine I can see all the ggml gptq model over here right you can run this all on CPUs okay with help of quantize models now you have four bit eight bit quantized models now we are also going to see two bit quantized models very soon again and you know carpathy has released a baby llama model you would have seen it right so the development it is happening in generative AI ecosystem is fantastic it has exceeded more slow as I said so if you want to learn more about llama 2 and couple of videos you probably would like to visit my YouTube channel uh and I'll maybe I'll go to my YouTube channel here okay on my YouTube channel then you you can look at couple of llama two models these two llama 2 video excuse me you can look at this couple of videos you know where you have how to use llama to put four different projects you can also look at my llm playlist I can see I have a playlist called large language model where I have 35 videos okay if you want to if you want to develop you know end-to-end projects or projects deployment everything whatever you want to learn in large language model I think project focused not too much of you know talk or you know too much of just talking like it's more on development if you want to develop a few of the things I want to work on projects have a look at some of the videos in llm playlist now what I'm going to do here is I'm going to first focus on pixels you can look at that this is what I'm going to look I'm going to utilize in this video for the article image I'm looking at an image but the reason I am using pixels is because not everybody would have a GPU machine to run a stable diffusion for example now if you have a good enough machine where you can you know run a image generation model like stable diffusion and related models you can also replace this this workflow of image generation it's not image generation we are just fetching the stock images with the help of an API but if you want to use the stable diffusion please go ahead and use it right if you have an open source model uh if you have a good uh vram or a GPU machine I'll recommend you to use stable diffusion and see you can also look at uh different uh imagination model you know on that maybe you can look at diffusers repository on hacking face to to get the diffusers model now what I'm going to do here I'm going to write first uh the code for image so let's have let's write something like fetch image dot pi now I'm writing a python file where I will write code for my uh image I'll face the image and the first thing that I'm going to do is I'm going to write import request I'm going to use the request modules in Python which will help you you know connect with the HTTP or https and try to get something from there you know that can be any type of content mostly text okay and now I'm gonna do is Define fetch let's write a python file a python function that's called Fetch photo and that will take query as an input pattern okay so input parameter I'm passing query and within that I'm going to write all of my you know code Logic the first thing that is I have to write the API key here so let me just do API key equals you know your API key you know I can just pass my API key because anyway it's okay uh if you not follow this practice maybe you can look at a different video that I have created where I have set the API keys and EnV file and then I'm using it from there but for this anyway I will delete it after this video now in the URI the first thing is https you have to look at their endpoint so if you come here on the pixels on the documentation you can look at there that's their pics that's their https endpoint that's the end point for all of their stock images now what I'm gonna do here I'm just gonna paste this over here V1 and then it's a search that's called search because they're going to search a photo based on a query that's my URI is you know or I don't know why I wrote URI you know it should be URL resource locator and then the URL and then I will give I'll write my headers okay so within this headers so my authorization are nothing but the API key I'm just going to you know authorize with my API key I'll just give my API key and I'm okay with headers now now I have saved my API keys and I have an URL where I can you know sort some of the photos based on the query so now we have to use that parameter right the query parameter so that's what I'm going to write here it's the params equals and it's again a key value period so we have to write in this form and give give it a key value and it's a dictionary right so what I'm going to do here is query and my query is nothing but we have to write query which is our input parameter in the function as so query as query and then I'm gonna only look at for page one so I'm just going to write per page one okay I don't need a lot of photos a single photo just to Showcase now you can play around it guys so response and in that response what I'm going to do is request dot get okay and uh request I'll just go okay so URL parents and my parents are not param so what I'm going to do here is unfortunately write headers so my headers equals headers and my bottoms equals bottoms now this is response now this is the response so we are using a request Library the request module in Python and we are going to use git because we are going to fetch a photo of fetch a data when we are you know when we are basically pushing some data that's going to use a post method okay but it doesn't necessarily mean that you can only use post for that purpose you can also use post depending on what kind of a lot of other things that goes behind git and post guys okay so you know if you look at the URL itself the browser URL even the number of input also plays a huge role so what kind of method you are using so if you if you're using get method then these browsers have you know limitations on the URL input so that's very good people a lot of people also uses post which gives you better you know uh length of tokens or words within their input URLs so that's API specification so now the response request dot get and now what I'm going to do here is I'm gonna check if the request was successful so let's write that so check check if the request was successful so basically 2 200 status code so status code is 200 or something like this okay now what I'm gonna do here I'm gonna say okay if response dot shutter score equals equals 200 then okay print all my data inside this okay now I have data so my data is nothing but the response so let me just write response dot Json because I'm expecting a Json value or Json so uh it's okay data request to response.json now I already know that what kind of data I get in pixels so I'm just going to write that extra line of code also but I will explain why I'm writing this code because I only need the original source of that image okay so what I'm going to do here is okay let's write photos Okay so photos equals data so we're gonna write data dot get and let's use a photo so the first thing is photos and then I'm gonna pass an empty list that's it photos and then an empty list and now within this if photo if there is a photo so you can just write a photos now what I'm gonna write is SRC let's write a variable SRC original excuse me it's a source original image I only need the uh URL of this image that I'm trying to fit because I can use that URL at a lot of other places to preview it to view it to pass it uh within the document right so either only need the URL of that so Source original URL and that is basically photos and the first one and within that I only need the SRC uh key of that and then I only need the original okay so I already know the format of pixel that I'm doing it but probably if you're doing it for the first time you should print the data response okay this data you should do a print data and see what you are getting for your learning purpose but I already know what kind of response I get in pixels now SRC original URL photos the first one uh the indexing and then the source and then the original okay now I'm just gonna return this so let's return so return Source original URL and now I'm just gonna write an else or else just do a print could know like something no no photo found or something no photos from okay if there is no photo for that query then it will get executed and it will say okay no photos found so that's why I'm doing this now what I'm going to do here is I'm going to write else for this as well you know the on the error code so if you get any other code you know error code I'll just gonna print it over here now error response uh plus status code something like this okay or let me just write in a better way so error and in this error let's have a key value pair so what I'm going to do is response the status code and then I'm gonna also give the response text okay that's what we get okay fine this makes sense now print response text and now let's return this guys so this is how the function will get written return I'm gonna return nothing if this gets okay so for error uh there is something wrong you know you cannot write like this so let me just do this I can also write here now this one will be here after error okay cool so this is okay now this this is the function of fetch photo which will get a photo from pixels based on your query or input or idea whatever we name it now what I'm gonna do here is I'm gonna use this so example of example images of this function or something like this so let's write this and now what I'm going to do here is I'm going to pass a query here so let's pass our query as quantum or something what should we write or let me write a circular economy okay so I'm just gonna write circular economy economic this is my query circular economy okay something you know with the sustainability now what I'm going to write is let's have a variable called Source original URL and then I'm gonna just use a function called Fetch photos and what about the function name excuse me search photo okay and in this fetch photo what I'm gonna pass is my query as an input parameter and query and now what I'm going to do is I'm just going to check if SRC original uh you can also do a not none or something but it's okay if SRC original then just print it okay now what I'm gonna print is the original you are okay let's write like this so original URL is source so let's write in a better way so original URL now let's write four then I'm gonna write my query so let's write query and then let's write okay so the query will be in this format so query so original URL for query uh you can also so why would you need colon here you don't need here so I will just give a space and I will give colon here okay so now I'll just keep a colon and Assassin's SRC original URL I'll close this and I will just close this cool that's it so the function is done okay we have written a function for fetch image dot Pi now what I'm going to do here is I'm just going to run this and see if this works okay so let me just let me just go to conductivate line chain I'm going to activate my line chain environment and I'm going to run this file so let's run this file python fridge underscore image dot pi and you can see that I got an image so fast I'll just maybe I can copy this right so let's copy this link guys and I'm going to copy this link and come here I'm gonna paste and see we'll get an image a fantastic image right the same image that I was showing in the beginning this is kind of save this same image of circular economy you can see right so good good enough image to keep in a PPT or an article right when you are writing it or posting it somewhere so we are done with our fetch image pi and this code will also be available if you want to use pixels for one of your use cases you know you can also utilize this but I'm going to write an app.pi function so let me just write an app.pi function here and in this Pi function I'm going to write all my code so all of my uh all of my uh code Logic for article will go inside this so I'm going to write everything in this app.pi so let's first bring some ranking thingies I'm going to use LMS input I'm going to use C Transformers because I'm gonna use I'm going to load this llm within I'm going to load a quantized gdml model through C Transformers which is a cc plus plus binding for Transformers which helps me load this model on a faster inference rate okay it also provide me a faster influence as well and so LMS Imports the Transformers and I'm gonna also have line chain dot chains I need llm chain so I'm going to use llm chain and then from line chain well import from template okay with line chain these are three requirements from line chain now what I'm going to do is having a string lead so input streamlit add St and then I also need import OS so let's do that so import OS and then I need from dockets from docx import uh document this is a library that will help us create that doc file okay in a docx format okay so from docx import document and then we also need one more thing from docx dot C let's see from docx say say your import inches you have to define the inches for the width within the document so from docx dot said and now also need an IO for buffer so import IO I have to save that buffer right guys text to put that in a document in stimulate so import IO and then I need pillow for as well for image so import image to open that image and then I'm gonna also need request so let's even request so import request that's it so this is what we need these are the dependencies guys first let's load the model so I'm going to load the model here so let's load the model I'm gonna just copy this code you know I'll go back to my GitHub repository and I'll see I can take llama to Medical chat bot and here I'll just go to to model and in this model I'm gonna just copy this load llm thingy I just need a single function from my one of the GitHub repository and that's it so what I'm doing here I have a function called load llm that I'm using a c Transformers function and within that I am passing my model my model name is glamor27b chat ggml model type is llama and I'm going to give a Max tokens of for example okay I'm let's write okay let's make some changes in this function guys okay let's people end user Define the max token maybe through prompt we can Define so let me just write Max tokens here so let me just like match tokens and then in here I can pass my Max tokens as an input parameter and I can also pass something called prompt template here so let's I'm not prompt so let's pass from template also so we're gonna passing two things we're gonna pass maximum number of tokens we are expecting as an article and also the prompt template and let's increase the temperature for you know to become to ask lava to become a little creative and you know to generate little creative responses and on the random randomness as well so let me just call it 0.7 okay to increase and then I'm not going to return llm here because we also have to do a few things so now what I'm going to do here I'm going to write a variable called llm chain so in this chain what I'm going to do I'm going to use llm chain from line chain and within this chain I'm going to write a few things the first is llm and this llm is nothing but the llm variable that I have defined above where I am loading the model through C Transformers now I'm going to use a prompt template so prompt template and in this prompt template from Dot from template okay Dot from underscore templates if I'm not wrong Temple yes and I'm going to pass from template that's it okay now I'm just going to return this llmj so this is the model code let's let's find this perfectly fine now what I'm going to do let's also copy this guys you know I've created fetch image dot Pi maybe I can read it from here also but let's paste it over here in a single file okay now we are getting this we don't need all of this thing so let me just remove this for now okay so this is okay now so what we are doing here we are returning this none okay now let's we have to write couple of more functions so the first function that we are going to write is we need one more function to create the world what document I'll just plug in my so let's write a function called Define uh create word doc or something okay create word doc the formatting dock X okay so create now it will take user input so let's write user input and this will take paragraph so paragraph user input and then you also take image input so let's write image input okay so these are the input parameters within that function now we need is uh we have to call that document that we have imported so doc document perfect this is basically uh if you are familiar with oop you know when we used to you know uh write code in Java we used to call Constructors whatever you will be different terminologies and different also the the function also the way it works right so don't get confused with it okay so dog equals to document and now what I'm going to do is I'm just going to add heading first so doc dot add and in that add underscore heading so it will help us add the heading within the doc file okay that we are creating this is nothing but our user input doc dot add heading um something is missing it's not one let me just hover over this function um I think it's I think it's level level one okay doc dot add heading uh is the input and level one and the next is Doc dot add paragraph so underscore Para graph graph and in this I'm gonna pass uh the paragraph that's it so this is what I have added so far within this doc document is the function that we are writing now the next is we are going to add the image into it so what I'm going to do is talk dot add heading so add heading I'm going to pass user input here we'll have you know uh image okay that's that's image is fine okay image and then I'm gonna pass level one again this is for layout guys okay the label that we are using now what I'm gonna do is I'm gonna I'm going to have an image stream image stream and this image stream is nothing but the io dot bytes that I'm gonna use uh excuse me i o dot bytesio yes and let's just call this function image stream of bytes IO and now the next is image input dot save so image input dot save and I'm going to save this image stream so image stream and then let's keep a PNG format for this that's it format PNG so image input dot save now the next thing is image input dot not close okay we have six so let's use seek see Zero image input dot sync and then let's add the picture so add underscore picture that's it if I I wrote it wrong doc dot add picture I'm gonna pass image stream and width width equals let's have some inches so what will be the width of that image that we are going to put in a document so let's have maybe three inch three will be a little lesser so we can have five or four so let's keep four phona and see what kind of images we are getting I think it's four so it's inches four and the next is let's just return the dock so dock that's it very simple but you can go through this live the library guys on GitHub I'll share the link in the description the dock X that we are using right the python dock X the docx library now you can go around it they have a lot of other customization you know mechanism that you can customize the app now what I'm gonna do is I'm gonna use if hd.set page config I want to use a white layout on my streamlit app what I'm going to do is config and I'm gonna pass layout equals wide layout equals wide and I'm gonna use a div man quickly you know in depth main within this I'm just gonna write pass for now and if a name underscore underscore main all my stimulate code goes inside this main function and the first thing is HD dot title and title is like you know article article generator app article generator app using llama excuse me at using llama2 that's it now if your title gamma 2 now what I'm gonna have use and user input and this user input is nothing but SD dot text input and in this text input the first thing I'm going to write is please enter your topic or idea for article for article generation that's it and then I'm gonna also have an image input so I'm gonna have image input and the same thing so I'll just copy this guys okay so image input and I'll just copy this for image generation for image another new generation I'm going to generate image okay we are just fetching an image if you want to use image generation model I will recommend you you should use stable diffusion go and use the diffusers model for each stable diffusion you know if you want to use completely open source because gamma 2 we are using its own open source if you don't want to use an API for fetching the image you can use the open source image generation model make complete open source app host it somewhere and sell it for guide sell it as a subscription for five dollar per month you know that's so many things that you can do as any as a startup idea right build a software as a service platform for article generation put some tones in prompt give tones option give the category of domain options you can customize this in a different way guys you know it's just how you imagine to build that application now if length user input and length image input greater than zero where there's a value inside it if there's no value then you know don't use don't execute the rest of the code okay call to call three and dividing this in three columns and then I'm gonna use HD dot columns and up I'm gonna use this one two one format okay give twice the double uh width through the middle column column two and in that I'm gonna write with column one and with column one what I'm gonna do is I'm gonna write all my code Logic for column one into this one so let's let's do that so with column one so so it's one what I'm going to do is HD Dot subheader and in that I'm going to write you know uh generate content or something okay generated content by llama too generally contained by lamba 2 this is my sub header and also write you know if you have to write uh you uh your submitted uh idea topic for article generation and I'm gonna just use this something like you know plus not a user or it's user input that's it this is for sure right for that image input and I'm gonna use this here not generation for image and this is image input and this is on the right okay so what I'm going to do now next is next is important so let's write a simple prompt so what I'm going to do here is I'm gonna write a prompt template uh prompt and within this I'm going to write my prompt and I'm going to say okay that you I'm going to give a role to a large language model so I'm going to say okay you are a digital marketing expert digital marketing and AC Ox for search engine optimization expert uh expert and your task is to generate I'll then do alt g generate articles generate articles you know uh articles for a given topic so so to write write an article write an article on and I'll give the topic name here I'm going to write my topic on topic uh something like this okay uh topic under 800 words your article must be well Lindy must be length of 800 words or 800 words this is okay 800 words stick to the topic given by the users above given by the user don't write about you never know that which line we are in right so we're not using slash n or something let's don't confuse a large language model okay guys it's true the topic given by the user and and maintain and maintain a professional professional but at the same time but at the same time creative tone creative tone so I've written up very simple prompt okay you can write even better prompt than this for this particular task and that's up to you and I'm leaving that to you but this is a simple prompt prompt template where we are saying okay we are giving a rule we are assigning a role to a large language model okay we're saying you are a digital marketing and SEO expert and you're also giving a task to it your task is to generate articles for given topics write an article on topic under 800 words so we are setting a higher limit of 800 where we have defined Max new tokens if you go on the uh go it over here and you can see the token that we okay we are not giving it over here that's fine so we have match tokens equals Max tokens file so we are going to use that in the below section your article must be length of 800 words stick to the topic given by the user and maintain a professional puzzle you can also give the option this this option on the UI itself the estimate interface or any other application that you are building so let users submit that guys let users submit that uh number of tokens basically one token means four characters okay in natural language on average on approx it's not final okay but that's what the industry says okay so you can also let user uh input this numbers and you can just let llms to generate the content now we are okay with it so let's have an llm call so what I'm going to do here and I'm gonna say okay llm call and I'm going to call this so load llm so load underscore element the function that we have and what are the function the function is load llm okay now we're going to pass two parameters within it okay because that's what we have said so match token so let's make itself explanatory here so max token as we have written in the prompt 800 but you can also take it from the end user okay so just have a input box or some have some number or something slider with number okay depends what you want to do and prompt template and the prompt template is nothing but okay if Y is coming capital I don't know okay Chrome template it might be something with the lantern or something I don't know okay prompt excuse me I don't know why I'm writing here prompt template over here so let me see my monitor prompt template okay from template and this prompt template is nothing but the prompt that I've written on top prompt template that's it here we go so we have our llm call now okay let's also print this llm call and see what are we getting into this so parallel code and now we're going to use a result variable let's call a result variable and then use this llm call so I'm going to write llm core I'm going to pass my user input within this so let's pass and user input that's it here we go so now let's do a validation check check if this llama if llama is not generating any content for this we should get an error so we should write an error handling mechanism as well we should have some error handling we will try except or something for now we can have an if a conditional so if length result greater than 0 it means if there is any value that llama has generated then just you know write that in info your article has been generated successfully or something if you're on info excuse me and if I'm gonna use it right here not you it's the result so I'm just going to write a result if you would write result if not just give us error here so else uh use SC dot uh error you can use the error message uh in extremely sorry we cannot we cannot generate articles for you for this topic or something okay let llm decide that okay I'm saying okay Airline is accountable for all of this okay I am not accountable okay sorry we could not generate okay if you want error and something that we can write okay uh oh sorry I wrote it outside I don't know why okay fine now we are done with this okay we're done with column one so let's write for column two for now okay so what I'm gonna do here and column two should be our simple thingy not much of thing in column two let's write a sub header here is your sub header and within this I'm gonna write my article image okay so your article articles [Music] faced image or something okay your articles faced image this is going to be my header for the second column okay the column two I'm gonna use my image URL here guys so email URL and I'm gonna use my stamped image that way I'm saving that image okay so let's write temp image temp image Dot temp image dot jpeg okay so here I'm gonna just write temp image dot jpeg and that's what I'm therefore I'm doing doing here guys okay fantastic fine so let me just bring my screen here for this okay image URL so temp image dot jpeg jpg not JPEG and then I'm gonna have our uh dock but that doing column three not in column two so let's just show that so SD Dot View and I'm just gonna show this image inside this so that will be your image URL okay so let's have one more column here guys so with column three the last one where we'll use it purple let's run this and see if you're getting any error or something because we get error when we write code now for this I'm just gonna have something like you know sub header okay and say you know coming soon not coming soon download your article or something download your article here we'll have that option to download your article and then we write path okay fine for now okay now this is okay now we have this couple of let's run this guys now so what I'm gonna do here is I'm going to write extremely run app dot by the file name and you can run it and you can see that we have something here okay we have called article generator app using llama2 and here you can please enter your topic or idea for the optical generation please enter your topic or idea for image one idea should we give you can uh I'm not sure let's give Quantum computing now you want to write a blog or article on Quantum Computing you can also write that you know through this app okay so I'm just also going to write Quantum Computing okay Quantum Computing I don't know why I am but my accent becomes like that Quantum okay so we have Quantum Computing and let's Quantum Computing for image I can write Quantum simulation now let's hit hint enter you can see please enter to apply so let's hit enter and see if we are getting any error it says name cool one is not defined you know okay this kind of typo I don't know how I become a programmer guys you know if I'm making this kind of silly mistakes okay name cold one so now what I'm gonna do here is I'm just gonna hit enter the game okay I'll just do a rerun okay it says load llm uh got an unexpected keyword argument okay uh which is prompt template okay let's see what have we given over here in load llm aha okay sorry this is not from template that's my bad ah okay that's why I was getting that you know uh that you know that time but now it should work fine uh okay there's somewhere something wrong with that okay now it will take little time because gamma 2 is you know running behind it so what I will do I'll pause the video because it will take 30 to 45 seconds I will resume once it gets completed guys okay and here you can see right we we got our uh response okay uh on both content and the image so on the content you can see your article has been generated successfully I think we should not say article here which will say your content has been generated article will come here okay we will work on the this one the article part now in column three I think we have to change the labels here we'll do that again we are writing the code and we got some good enough text guys you know you can again play with the prompt the more you play with the prompt better responsible get prompts are unexplored okay right now people are jailbreaking systems with prompt itself rather than going into the architectures you know they are just prompting and playing with it breaking the system now you can also see where your articles faced image doesn't look like a Quantum related image to me but I think I made a mistake here on stimulation because it's showing some simulation some simulated screens over here but this makes sense you know you can at least you can use this as a storytelling okay because we are not using an AI generated image we're just fetching it through some stock images sorry stock images repositories okay and again you can change it over there it's not a problem now let's let's make a couple of changes here guys so the first thing is maybe we can change not your article your content your content has been generated successfully we could not generate content for contents for ignore generate content for this topic now here comes our column three is pretty much straightforward will not spend um a lot of time on column three so what I'm gonna do here is I'm gonna write you know so we need couple of things the first thing is image input and your image input is nothing but the temp image that you can see okay so I'm just gonna use temp image so temp underscore IMG jpeg jpg not jpeg sorry image input and then my dock so my Dock and I'm going to write the doc uh so doc and my dock is the function that I'm gonna use so it's create word docx okay this is my function create doc dockets I'm going to pass my user input I'm going to pass my image input of course we'll pass the image input through pillow of course through pillow so first thing that we have to do also to write a result and we only need the text for this so let's write text and the result is a variable that you can see it over here that we have in line number 97 right the result which have has the content okay so result text and here I'm gonna use pillow here so image dot open and within this open I'm gonna pass my image input that's it we're gonna have this image within a dock okay so this is the dock now let's save the save the word uh dock okay uh save the word uh document Word document uh to uh bytes IO buffer okay so I'm gonna have in the buffer so for that what we're gonna do is Doc underscore buffer and in that buffer IO dot bytes IO excuse me I don't know what this type of Iota bytes IO and knock underscore buffer and the next thing is I'm gonna have remember to save this so I think it's doc let me see if I have save here okay we have save as a class and we're gonna fast dog buffer we're gonna save this and let's seek so talk about the seek okay that's it so we are okay with it now we have to create a download button okay so let's write extremely download button or something button okay now SD dot download they have a download button option and within this you can write label first what will be the label of this but button I'm gonna say download article download your article or something okay this is your label I have to keep comma after this okay it's it's success parameters and then your data is nothing but your data is dock buffer so let's write this dog buffer and then your file name so my file name is nothing but the document doc let's write documents like you know Dog final or something okay doc final dot dot X that this is my docx and then I need an mime or the mine for this and I think okay application is good so let's see if tab 9 can suggest that not octet stream I need vnd yes but open Excel Office document dot spread not spreadsheet till this it's fine formats office okay down to open XML formats office documents or document and then I need Word document so word yes word processing XML World processing not XML word processing ml or something okay word processing yes this is what I need this makes sense okay now that's it we are done with this guys so now let's do one thing let's run this again and see if we are getting a download so right now if you see we are waiting for this download your article so what I will do I will again rerun it because again it will take at least 30 to take 30 to 40 seconds for the entire workflow to get completed so I will run it again and I will start once you know it it gets completed okay so you can see that you know we have our download your article uh button here where you can download the entire docx file which contains this content on Quantum Computing and this General fixed image that we have faced now download your article but before that also there was a changes I made couple of line changes here okay uh because you are not saving that file okay that uh temp image.jpg so we are passing that now here itself okay uh through IO Dot bytesio and image response dot content so what I did earlier it was temp image.jpg so now I have that because I was getting some error now in this image response I'm getting this image URL request dot get image URL and now I'm converting it to a bytes i o buffer and that's holds our image now and that we are passing it image here that's the line of changes that I made okay here in the code simple thing so this image URL is already on the internet so we are getting that again through a request module you know and then we have we are using pillow image to open that image the and when we are having the buffer of that image okay image response dot content and then we are putting that in inside this create what docx function so we can have a final docx file with the user input the text and the image that's what we are getting here guys okay uh simple thing that's that's two lines of changes okay so that what I did and now if you see we have our download your article thing over here which downloads the file docket doc final one docx or something okay so I'll just I'll just open this file okay now once I open this file you can see a beautiful you know uh article that we have got okay how does Quantum Computing Works uh topic Quantum Computing is a rapidly growing field that has gained significant attention in recent years due to its potential to revolutionize Computing and solve complex problems that are currently unsolvable you know with traditional computers in this article we will explore what Quantum Computing is and how it works and potential applications so it could not complete potential application but you can play with the max tokens and frequency penalty Etc you know to get this longer or the lengthier okay or the way you design The Prompt now we're getting what is quantum Computing how does fun of computing works and then we have an image input the image for that and we're getting this in a docx file now you can edit this you can put your own perspective or thought within this and you can create a powerful perspective out of it and that too is an open source last language model that's what the main agenda was right guys so you have this docx file now which has been stored here in this uh folder in the download folder you can see it over here fantastic so this is what we this is what we are looking for right so that simple kind of change in the uh this couple of line to put that image in the docx file we are using a large language model and we have created this you know very beautiful robots very powerful application that you see it over here okay article generator app using llama2 where you where the end user submits their idea topic it generates the content fixed faces and image and then also gives you option to download that particular docx file that you have created right that you have generated here so this is what I wanted to do in this video guys I wanted to cover this you know I'm also working on a couple of other videos that how you can create an automated PPT as well and that we can also send it to over mail or something so PPT generation using llama to Python pptx and stable diffusion for example okay that that video is also coming soon so stay tuned if you are looking for some open source based PPT generation app Okay so uh that's all for this video guys you know I hope you uh like the content of this video if you liked it please you know hit the like icon and uh if you haven't subscribed the channel here to subscribe the channel you can also look at different other videos in the llm playlist over my channel and please share the video and Channel with your friends and to peer and the code will be given to other this code will be given in the uh this through GitHub in the uh video description please go ahead and take the code base from GitHub and you can extend this further let me know what you you know build on top of it that's all thank you so much for watching guys see you in the next one
Info
Channel: AI Anytime
Views: 1,802
Rating: undefined out of 5
Keywords: llama2, llama 2, meta llama, python, coding, ai, generative ai
Id: MUADZ97GgZA
Channel Id: undefined
Length: 55min 21sec (3321 seconds)
Published: Sat Aug 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.