Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_openai import ChatOpenAI
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
from langchain.chains import LLMChain
|
4 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
5 |
+
|
6 |
+
def generate_script(prompt,video_length,creativity,api_key):
|
7 |
+
|
8 |
+
title_template = PromptTemplate(
|
9 |
+
input_variables = ['subject'],
|
10 |
+
template='Please come up with a title for a YouTube video on the {subject}.'
|
11 |
+
)
|
12 |
+
|
13 |
+
|
14 |
+
script_template = PromptTemplate(
|
15 |
+
input_variables = ['title', 'DuckDuckGo_Search','duration'],
|
16 |
+
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} '
|
17 |
+
)
|
18 |
+
|
19 |
+
|
20 |
+
llm = ChatOpenAI(temperature=creativity,openai_api_key=api_key,
|
21 |
+
model_name='gpt-3.5-0125')
|
22 |
+
|
23 |
+
|
24 |
+
title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True)
|
25 |
+
script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True)
|
26 |
+
|
27 |
+
|
28 |
+
search = DuckDuckGoSearchRun()
|
29 |
+
|
30 |
+
title = title_chain.invoke(prompt)
|
31 |
+
|
32 |
+
|
33 |
+
search_result = search.run(prompt)
|
34 |
+
script = script_chain.run(title=title, DuckDuckGo_Search=search_result,duration=video_length)
|
35 |
+
|
36 |
+
return search_result,title,script
|