Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
6 |
+
|
7 |
+
# Function to generate video script
|
8 |
+
def generate_script(prompt,video_length,creativity,api_key):
|
9 |
+
|
10 |
+
# Template for generating 'Title'
|
11 |
+
title_template = PromptTemplate(
|
12 |
+
input_variables = ['subject'],
|
13 |
+
template='Please come up with a title for a YouTube video on the {subject}.'
|
14 |
+
)
|
15 |
+
|
16 |
+
# Template for generating 'Video Script' using search engine
|
17 |
+
script_template = PromptTemplate(
|
18 |
+
input_variables = ['title', 'DuckDuckGo_Search','duration'],
|
19 |
+
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} '
|
20 |
+
)
|
21 |
+
|
22 |
+
llm=HuggingFaceEndpoint(
|
23 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
24 |
+
HUGGING_FACE_API=api_key,
|
25 |
+
timeout=500
|
26 |
+
)
|
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.invoke(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
|