Spaces:
Running
Running
Commit
·
c66af70
1
Parent(s):
256556c
Upload 2 files
Browse files- utils2.py +41 -0
- video2.png +0 -0
utils2.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,tasktype,api_key):
|
8 |
+
|
9 |
+
# Template for generating 'Title'
|
10 |
+
title_template = PromptTemplate(
|
11 |
+
input_variables = ['subject','tasktype'],
|
12 |
+
template='Please come up with a title for a {tasktype} on the subject: {subject}.'
|
13 |
+
)
|
14 |
+
|
15 |
+
# Template for generating 'Video Script' using search engine
|
16 |
+
script_template = PromptTemplate(
|
17 |
+
input_variables = ['title', 'DuckDuckGo_Search','duration', 'tasktype'],
|
18 |
+
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} '
|
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(subject=prompt,tasktype=tasktype)
|
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,tasktype=tasktype)
|
39 |
+
|
40 |
+
# Returning the output
|
41 |
+
return search_result,title,script
|
video2.png
ADDED
![]() |