JamalAG commited on
Commit
40bb928
1 Parent(s): 82cd2e1

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +44 -0
utils.py CHANGED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.llms import HuggingFaceHub
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
+ model_kwargs = {
23
+ 'temperature': creativity
24
+ }
25
+
26
+ llm = HuggingFaceHub(repo_id ="HuggingFaceH4/zephyr-7b-gemma-v0.1", model_kwargs = model_kwargs)
27
+
28
+ #Creating chain for 'Title' & 'Video Script'
29
+ title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True)
30
+ script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True)
31
+
32
+
33
+ # https://python.langchain.com/docs/modules/agents/tools/integrations/ddg
34
+ search = DuckDuckGoSearchRun()
35
+
36
+ # Executing the chains we created for 'Title'
37
+ title = title_chain.run(prompt)
38
+
39
+ # Executing the chains we created for 'Video Script' by taking help of search engine 'DuckDuckGo'
40
+ search_result = search.run(prompt)
41
+ script = script_chain.run(title=title, DuckDuckGo_Search=search_result,duration=video_length)
42
+
43
+ # Returning the output
44
+ return search_result,title,script