Skip to content

Commit

Permalink
tutorial115
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed Sep 24, 2024
1 parent 3c119fe commit bd0174e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 6 deletions.
11 changes: 6 additions & 5 deletions tutorial114/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import time
client=LumaAI()
video_metadata=client.generations.get(id="3b3ef40c-5cfb-4d0e-a4d1-63b4b132c5bd")
link=video_metadata.assets.video
response=requests.get(link,stream=True)
file_name="video.mp4"
with open(file_name,"wb")as f1:
f1.write(response.content)
print(video_metadata.state)
# link=video_metadata.assets.video
# response=requests.get(link,stream=True)
# file_name="video.mp4"
# with open(file_name,"wb")as f1:
# f1.write(response.content)

Binary file added tutorial115/__pycache__/genrate_video.cpython-39.pyc
Binary file not shown.
36 changes: 36 additions & 0 deletions tutorial115/genrate_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from lumaai import LumaAI
import time
client=LumaAI()

def generateVideo(input):
response=client.generations.create(prompt=input)
id=response.id
while(1):
metadata=client.generations.get(id=id)
print(metadata)
if metadata.state=="completed":
return id
else:
time.sleep(15)


def extendVideo(input, id):
response=client.generations.create(
prompt=input,
keyframes={
"frame0":{
"type":"generation",
"id":id
}
}
)
id=response.id
while(1):
metadata=client.generations.get(id=id)
print(metadata)
if metadata.state=="completed":
return id
else:
time.sleep(15)


41 changes: 41 additions & 0 deletions tutorial115/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from lumaai import LumaAI
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
import streamlit as st
from genrate_video import generateVideo,extendVideo
import time
st.title("VIDEO GENERATOR APP")
duations=[5,10,15,20]
selectd_duration=st.selectbox("your option",duations)
input=st.text_area("enter your subject")
llm=ChatOpenAI(model="gpt-4o")
template="you are intelligent and creative agent who can expression imaginary thought about {input} in a single line with minimunm words"
prompt=PromptTemplate.from_template(template)
client=LumaAI()
chain=prompt|llm
if input is not None:
btn=st.button("submit")
if btn:
response=chain.invoke({"input":input})
video_prompt=response.content
st.write(video_prompt)
ids=[]
n=int(selectd_duration/5)
print(n)
for i in range(int(selectd_duration/5)):
if i==0:
first_id=generateVideo(video_prompt)
st.write(f"{i}th id is {first_id}")
ids.append(first_id)
else:
next_id=extendVideo(video_prompt,ids[-1])
st.write(f"{i}th id is {next_id}")
ids.append(next_id)
final_id=ids[-1]
final_meta_data=client.generations.get(id=final_id)
link=final_meta_data.assets.video
st.write(link)
time.sleep(10)
st.video(data=link,autoplay=True)


Binary file added tutorial115/tutorial115.pptx
Binary file not shown.
2 changes: 1 addition & 1 deletion tutorial2/single_url.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from langchain.document_loaders import youtube
import io

loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/5z4VvNCEuuk")
loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/5CsTJEMvrrM")
docs=loader.load()
print(docs)
with io.open("transcript.txt","w",encoding="utf-8")as f1:
Expand Down
1 change: 1 addition & 0 deletions tutorial2/transcript.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Music] [Music] what's up guys this is Ronnie welcome back to our Channel Total technology Zone this is tutorial 114 and today's topic will be very interesting and in this tutorial I will show you how to integrate dream machine from Luma AI with Lang chain so nowadays I can see there are lot of uh content creators are creating video on Luma Ai and I got multiple request um from my channel that uh how to integrate or how to create videos programmatically using Luma AI right so Luma AI basically uh basically Luma is what that is what I'll be going to show you first and then we'll be going to do something with Lang chin I mean we'll try to integrate the Lang and see what are the output okay so without wasting much time let's start working with the Luma AI so this is their website Luma labs. and basically uh they have something called dream machine and basically this is an AI model that makes high quality video realistic video from Tex images means you can create video from text or you can even create video from images right so that is what you can easily access the their promt you guys can easily access their prompt you can try now you can click on try now and after that you have to click on API but there are some cat like if you want to use their API key then you have to do some sort of recharge but if you can if you want to try out their console you can easily do it okay but I'll be just going to show you how to actually access this using um their API key because we want to do something programmatically because we are programmer or we are llm Developer we want to develop something for the company so we'll be going to do the real stuff okay so first you go here and after that you have to click here basically if you see I have already us and after that I did something so I have right now 4.21 us so something and here if you click on this API key if you see this is my API key I created you you can create API key from here and once your API key is created then what you have to do to go here like like for Windows and after that go here and advance system sets environment variable and after that there is something called this we have to set thing Luma aore apore that's you don't have to do anything okay means you have to have to create your API key copy the key and within Windows system variable uh inside here uh environment variable within there you have to fit this thing like that okay and your job is done and once this is done then probably uh you can go to documentation you will see a lot of stuff but uh let me just minimize this thing and show you something from my uh vs code okay let me minimize this thing minimize with this thing here and uh probably you have to actually instop install this thing install L that's it then you can easily access that Dre Machine model okay and source code is actually available here I'll be not going to waste much time on the theoretical part because this is very interesting and nowaday it is kind of trending everywhere like not only on YouTube it is trending on uh LinkedIn it is trending on Twitter it is trending on Instagram it is trending on lot of other social networking sites even in Facebook as well like people are creating a very realistic video using Dre not only the Educators not only the technology freak uh like a technology geek people like normal content creators like generic content creators like those are actually into the field of digital marketing Market media Etc they all of them are using this um Luma AI machine a little bit expensive but their content quality is very very like brilliant okay let me do it from L right first thing first uh what we'll do we'll be going to actually ask uh uh ask for a prompt from lch and with the help of that prompt we'll be going to create a video and after that we'll download the video and see okay okay so let's do something uh first thing first uh let me uh write down the code here so it actually from uh from Luma AI okay import import Luma AI right and then you have to set up a client so client is nothing but the instance of this Lum that's it if you have not set your AP this line will give error but if you see here for me it is not going to give the because my AP is already set okay then there is something called this generation okay so what we'll do we'll be going to create something called generation like this and after that uh what we'll do we'll be going to like this okay and basically uh this is uh going to create the main thing okay so let's say Let's uh let me write response equal store client this client client dot Generations do create right and here we'll be going to just write prompt and prompt will be passed from here input okay that's it this is going to be input right if you run this thing this is going to generate the thing okay and once this thing is done you have to actually uh get the ID okay so ID equals to response uh response uh I believe it will be uh response. ID if I'm not wrong right okay this is done and once this thing is done let's wait for some time okay so what you can do we can print two things we can print the ID and we can print the response okay these two things we can response but just because um this will take some time so what I'll do I'll be just going to uh wait for some time so time import time so uh basically um just hold on and are you basically okay I I'll show you something are couple of are there but you guys have to understand that okay so that you guys have to understand so I'm just thinking so client this is the ID and then uh then basically I don't need this response sorry so what I do uh video okay uh response or maybe I can just write video metadata okay okay like this so video metadata will come come from client okay dot uh Generations dog and there I'll be just going to use ID equals to something okay right so this ID will be ID okay so let's wait for some time and we'll see okay so what I'll do first I'll be going to write this thing video metadata okay and here before I generate this line I'll be going to wait for some time okay why I'm waiting I'll show you later let's just generate this line so this is my function this is going to use this thing now uh run this function I want to actually I want to call this function from my another function so let me actually write this thing as generate generate video okay generate video. py and another one is actually llm basically this is my main LM okay so what I do from L chain uh openai import that open right then from Len len. proms import PR template and I want to actually import this one so from generate video import uh generate video okay video now what I'll do uh I'll be just going to create the llm first so this is going to be chat form template sorry chat openi and inside that my model will be uh4 okay okay now let's create a template okay the template what we will write you are and intelligent uher intelligent and creative thinker thinker who can express Express imaginary imagination in small in in one line with minimum words who can express his imagination in one line with minimum words can express you can express about in one line with minimum word okay now my template now just going to write a prompt prompt will be prompt template dot prom template okay inside I'll be just going to write template right now what will happen just going to create a variable called gen and it is going to be uh prompt and then this pipe LM so I make I'm using LCL basically then response equals to chain do content sry chain do invoke input equals to input right all done now now what will happen uh I have to call this generate video function generate video with response do content but before that I just want to print this thing okay what will happen if I execute this thing this is going to call this function and later on it is going to print the ID of the generated video and the metadata why this metadata is important I'll show you so basically when when when it is actually running this thing with this prompt started generating the video immediately video will not be available maybe the statuses there are various status of video like kind of in the queue or maybe in the thinking mode then processing mode and then uh active mode so I just want to download the video when it is active so that is why this metad data is very much important okay so this is a very early stage of using their API and I believe in the upcoming videos we'll be going to do a lot of things with this uh API so I just want to actually uh start from the very Basics and slowly slowly we'll be going to integrate this thing with langen okay why I'm using langen because you cannot create U like when you're joining the company always you have to take uh help from some sort of framework llm framework and I think at this moment L chain is one of the most mature framework so that is why I'm trying to do everything with respect to Lang chain I I mean in in terms of integration okay so let's start uh writing now so this thing let's execute this thing and let's see so before uh generating this thing let's execute uh let's execute this thing this will int going to call this generate video okay so right let's do okay there is some error if you see here okay so I think yeah so input requires a value I forgot to actually give the value so snowy snowy New York snowy night s night night of of Chicago Chicago okay let's see so let's see uh what is this I don't know inut this in invoke input input this this this oh my God I don't know what is happening uh why this is giving the error I don't know from template template template is there prompt is oh sorry I forgot it is prompt Mt right so now this will work okay let's see okay okay see this is the thing now I got the video video generation started if you see here the state is dreaming means it's thinking right and this is the ID of the video If you see here this is the ID this is the ID now I got the ID of the video okay so with the ID of the video we can easily do it so what what needs to be done I'll show you how to actually do it so basically now uh what you can do um you don't have to run this thing here uh okay let's do something I'll show you so let's create another program called test.py okay I got the video ID remember so video ID is here okay got the video ID okay what you do here so we need this thing just remember we just need this thing okay right and we need one more thing that is this one okay okay video metadata and here what you have to do you have to copy this ID this ID okay just hold on let's copy this ID okay done and then we be going to print the video okay so basically if you see here in the asset section it is showing none once a v is ready you will be going to see an URL here okay so let's close this thing close this thing let's execute this thing okay so if you see here now I getting that asset asset is actually having value and status is completed so right let's copy this thing and follow the link and open so let's see okay so this is a 5sec video so this is slow night in Chicago right this is super cool and amazing right guys so with the help of L chain I just created a video with um uh with dream uh machine from uh Luma AI now the next question is actually probably you guys will have how to download this video right so this video is actually having link of this so maybe I can just right assets uh in the assets uh uh let's see what it is actually going to write okay so this is actually this assets so maybe I have to write something called uh video this is going to give me the link okay okay so I got the link now you have to download this thing I'm just showing you everything in bit and PES and in the next tutorial what we'll do we'll be going to create a stream application there will be going to P the video in the UI okay so this is a link actually okay now you have to download this video okay so link is here now what what have to be done so we need to download this thing right so downloading is very easy we have to call this URL and that's it so uh first thing first we have to write a variable called response response equals to requests get and Link means this URL right then I want to actually uh uh open the stream stream equals to True okay because I need to video has to be like download like that you have to open the stream mode and then there will be something called file uncore name okay this is going to be link right plus maybe I can just simply write like this uh say um uh okay so I don't need this like let me just give a simple name video. MP4 okay okay so now to open whatever I got response that I have to open in a binary mode in a right binary mode and then we'll be going to do it so with open right with open so what we'll be open we'll be going to open this uh this file name so this uh this video basically okay uh let's see um just hold on let's say video. MP4 okay and how we'll be going to open as a binary mode WR binary okay right because we'll be going to write this as a binary f file I mean as as F1 is also fine right F1 WR you want to write you want to write response content so this response content okay I'm inan this one this response content I have written now this is done so basically I can simply write this thing as F name oh I don't know what is happening here let me write this file name okay everything is fine let's execute this thing and we'll be going to see a file here okay let's see let's execute execution started in few seconds see the video is created here let's now play it it's there that's it so super cool and amazing right so first what happened here LM I got this prompt so what was prom so s FL something like that under Chicago so many different things up there right okay so that's it and I want to show you how much actually it cost maybe if I go to us it so we'll be able to see it because I just now generated and few minutes ago it was 4. something now let's see how much credit was there 4.21 was there before the video now it is 3.81 so almost 40 4 cents or4 sorry uh4 us has been uh Lu deducted so if you are from India then probably uh in in our currency it is actually almost close to 30 or 35 rupees for one 5sec video it is very very expensive but you know when you are going to do something uh like beautiful amazing then this thing you have to pay so I can imagine like uh with this AP key uh if I want to actually generate a like Instagram reel for 45 seconds and probably I have to pay 10 us right right but I believe that video will be super cool and amazing right and and and one more thing I'm not sure whether they have this Lim lip sync or audio Integrations are available or not if not then probably you have to use some other tool to make your video more like beautiful and stunning because nowadays a lot of big companies are actually using this sort of tools for generating their content they are not relying on some video houses or something U something like human driven they have their AI Engineers are ready with this sort of tools they purchase one year license and it is way cheaper than hiring 10 people right you just have to give the prompt it will think and it will do and if you don't like it you have the option right okay with that note I'll be just going to conclude video over here hopefully you guys like this video and if you're watching first time for this channel guys please go and uh look for my playlist Lang Channel Lama index you can see that I have created more than more than 100 114 videos on Lang and in this video I just created something very unique and this is right now in train a lot of uh a lot of my students are actually requesting me to do some sort of integration with langen and Luma AI so I thought of creating this video but one request guys please try to subscribe to my channel hit the like button share my videos with your family and friend and don't forget to hit the Bell notification so you should not miss this sort of amazing video from my future update as well and if you if you like something in the video and if you're thinking these videos are helping you please put some comment so that YouTube algorithm will find this video beneficial and other people also get uh the visibility towards this video and last but not least I want to request you guys please please try to subscribe to my channel because your one subscription will help me to grow and the moment YouTube see that people are start subscribing YouTube algorithm is also going to push my videos to the large number of audience and my ultimate goal is to reach large number of people so guys please help me to grow and I'm promising I'll always come back with this sort of amazing and meaningful videos okay with that note I'm just going to conclude the video over here we'll see you in the next video till then take care goodbye have a nice day happy learning oh [Music]

0 comments on commit bd0174e

Please sign in to comment.