1
+ from langchain .llms import OpenAI
2
+ from langchain .prompts import PromptTemplate
3
+ from langchain .chains import LLMChain
4
+ from langchain .tools import DuckDuckGoSearchRun
5
+
6
+ # Function to generate video script
7
+ def generate_script (prompt ,video_length ,creativity ,api_key ):
8
+
9
+ # Template for generating 'Title'
10
+ title_template = PromptTemplate (
11
+ input_variables = ['subject' ],
12
+ template = 'Please come up with a title for a YouTube video on the {subject}.'
13
+ )
14
+
15
+ # Template for generating 'Video Script' using search engine
16
+ script_template = PromptTemplate (
17
+ input_variables = ['title' , 'DuckDuckGo_Search' ,'duration' ],
18
+ template = 'Create a script for a YouTube video based on this title for me. TITLE: {title} of duration: {duration} minutes using this search data {DuckDuckGo_Search} '
19
+ )
20
+
21
+ #Setting up OpenAI LLM
22
+ llm = OpenAI (temperature = creativity ,openai_api_key = api_key ,
23
+ model_name = 'gpt-3.5-turbo' )
24
+
25
+ #Creating chain for 'Title' & 'Video Script'
26
+ title_chain = LLMChain (llm = llm , prompt = title_template , verbose = True )
27
+ script_chain = LLMChain (llm = llm , prompt = script_template , verbose = True )
28
+
29
+
30
+ # https://python.langchain.com/docs/modules/agents/tools/integrations/ddg
31
+ search = DuckDuckGoSearchRun ()
32
+
33
+ # Executing the chains we created for 'Title'
34
+ title = title_chain .run (prompt )
35
+
36
+ # Executing the chains we created for 'Video Script' by taking help of search engine 'DuckDuckGo'
37
+ search_result = search .run (prompt )
38
+ script = script_chain .run (title = title , DuckDuckGo_Search = search_result ,duration = video_length )
39
+
40
+ # Returning the output
41
+ return search_result ,title ,script
0 commit comments