Rhino66 commited on
Commit
aee97f9
Β·
verified Β·
1 Parent(s): 12f874f

Upload 6 files

Browse files
Files changed (6) hide show
  1. .env +1 -0
  2. .env.example +1 -0
  3. app.py +59 -0
  4. requirements.txt +0 -0
  5. utils.py +43 -0
  6. youtube.jpg +0 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY = ""
.env.example ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY = ""
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import generate_script
3
+
4
+ # Applying Styling
5
+ st.markdown("""
6
+ <style>
7
+ div.stButton > button:first-child {
8
+ background-color: #0099ff;
9
+ color:#ffffff;
10
+ }
11
+ div.stButton > button:hover {
12
+ background-color: #00ff00;
13
+ color:#FFFFFF;
14
+ }
15
+ </style>""", unsafe_allow_html=True)
16
+
17
+
18
+ # Creating Session State Variable
19
+ if 'API_Key' not in st.session_state:
20
+ st.session_state['API_Key'] =''
21
+
22
+
23
+ st.title('❀️ YouTube Script Writing Tool')
24
+
25
+ # Sidebar to capture the OpenAi API key
26
+ st.sidebar.title("πŸ˜ŽπŸ—οΈ")
27
+ st.session_state['API_Key']= st.sidebar.text_input("What's your API key?",type="password")
28
+ st.sidebar.image('./Youtube.jpg',width=300, use_column_width=True)
29
+
30
+
31
+ # Captures User Inputs
32
+ prompt = st.text_input('Please provide the topic of the video',key="prompt") # The box for the text prompt
33
+ video_length = st.text_input('Expected Video Length πŸ•’ (in minutes)',key="video_length") # The box for the text prompt
34
+ creativity = st.slider('Creativity limit ✨ - (0 LOW || 1 HIGH)', 0.0, 1.0, 0.2,step=0.1)
35
+
36
+ submit = st.button("Generate Script for me")
37
+
38
+
39
+ if submit:
40
+
41
+ if st.session_state['API_Key']:
42
+ search_result,title,script = generate_script(prompt,video_length,creativity,st.session_state['API_Key'])
43
+ #Let's generate the script
44
+ st.success('Hope you like this script ❀️')
45
+
46
+ #Display Title
47
+ st.subheader("Title:πŸ”₯")
48
+ st.write(title)
49
+
50
+ #Display Video Script
51
+ st.subheader("Your Video Script:πŸ“")
52
+ st.write(script)
53
+
54
+ #Display Search Engine Result
55
+ st.subheader("Check Out - DuckDuckGo Search:πŸ”")
56
+ with st.expander('Show me πŸ‘€'):
57
+ st.info(search_result)
58
+ else:
59
+ st.error("Ooopssss!!! Please provide API key.....")
requirements.txt ADDED
Binary file (288 Bytes). View file
 
utils.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #from langchain.llms import OpenAI
2
+ #The above is no longer avialable, so replaced it with the below import :)
3
+ from langchain_openai import ChatOpenAI
4
+ from langchain.prompts import PromptTemplate
5
+ from langchain.chains import LLMChain
6
+ from langchain_community.tools import DuckDuckGoSearchRun
7
+
8
+ # Function to generate video script
9
+ def generate_script(prompt,video_length,creativity,api_key):
10
+
11
+ # Template for generating 'Title'
12
+ title_template = PromptTemplate(
13
+ input_variables = ['subject'],
14
+ template='Please come up with a title for a YouTube video on the {subject}.'
15
+ )
16
+
17
+ # Template for generating 'Video Script' using search engine
18
+ script_template = PromptTemplate(
19
+ input_variables = ['title', 'DuckDuckGo_Search','duration'],
20
+ 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} '
21
+ )
22
+
23
+ #Setting up OpenAI LLM
24
+ llm = ChatOpenAI(temperature=creativity,openai_api_key=api_key,
25
+ model_name='gpt-3.5-turbo')
26
+
27
+ #Creating chain for 'Title' & 'Video Script'
28
+ title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True)
29
+ script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True)
30
+
31
+
32
+ # https://python.langchain.com/docs/modules/agents/tools/integrations/ddg
33
+ search = DuckDuckGoSearchRun()
34
+
35
+ # Executing the chains we created for 'Title'
36
+ title = title_chain.run(prompt)
37
+
38
+ # Executing the chains we created for 'Video Script' by taking help of search engine 'DuckDuckGo'
39
+ search_result = search.run(prompt)
40
+ script = script_chain.run(title=title, DuckDuckGo_Search=search_result,duration=video_length)
41
+
42
+ # Returning the output
43
+ return search_result,title,script
youtube.jpg ADDED