arshabbir commited on
Commit
76b272b
β€’
1 Parent(s): bd3c034

Initial commit

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