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