File size: 3,007 Bytes
d29a64f
 
 
 
58fa0a3
d29a64f
58fa0a3
f3755b9
d29a64f
 
58fa0a3
 
d29a64f
58fa0a3
d29a64f
 
58fa0a3
 
 
 
 
d29a64f
 
58fa0a3
d29a64f
58fa0a3
 
 
 
 
d29a64f
 
58fa0a3
 
 
d29a64f
58fa0a3
d29a64f
58fa0a3
 
 
 
 
 
 
 
 
 
 
d29a64f
 
58fa0a3
 
 
 
 
d29a64f
58fa0a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import streamlit as st
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.memory import ConversationBufferMemory
from langchain.utilities import WikipediaAPIWrapper



st.title("YouTube Context Explorer")
prompt = st.text_input("Plug in your YouTube topic here")

# Prompt Templates [Title]
title_template = PromptTemplate(
    input_variables=["topic"],
    template="""Given the topic {topic}, you are tasked with generating five engaging content suggestions
    for a YouTuber in less than 20 words. Use your expertise in content creation to propose ideas that are captivating and 
    suitable for a wide audience, ensuring each suggestion is distinct and offers a unique perspective or 
    approach to the topic.
""",
)

# Prompt Templates [Script]
script_template = PromptTemplate(
    input_variables=["title", "tags", "wikipedia_research"],
    template="""You are a specialist in crafting engaging scripts for YouTubers. Given the title {title} 
    and incorporating the keywords/tags {tags}, while leveraging this wikipedia reserch:{wikipedia_research}, 
    your focus is to initiate the script with the most captivating aspects while maintaining a friendly tone throughout.
    Your expertise lies in creating content optimized for 5-minute or700 words long videos.""",
)

#
llm = OpenAI(temperature=0.5)
title_chain = LLMChain(llm=llm, prompt=title_template, output_key="title", verbose=True)
script_chain = LLMChain(
    llm=llm, prompt=script_template, output_key="script", verbose=True
)
wiki = WikipediaAPIWrapper()

# Initialize session state variables
if "selected_title" not in st.session_state:
    st.session_state.selected_title = None
if "wiki_research" not in st.session_state:
    st.session_state.wiki_research = None
if "tags" not in st.session_state:
    st.session_state.tags = None
if "titles" not in st.session_state:
    st.session_state.titles = []

if prompt:
    # Check if the titles need to be regenerated
    if not st.session_state.titles or (st.session_state.get("last_prompt") != prompt):
        title_suggestions = title_chain(prompt)
        st.session_state.titles = title_suggestions["title"].split("\n")[1:]
        st.session_state.last_prompt = prompt

    st.session_state.selected_title = st.radio(
        "Select a title:", st.session_state.titles
    )
    st.write(f"You selected: {st.session_state.selected_title}")
    tags = st.text_input("Enter tags (comma separated):") or "No tags provided."
    if st.button("Submit"):
        if st.session_state.selected_title:
            wiki_research = wiki.run(st.session_state.selected_title)
            tags = tags or "No tags provided."
            script = script_chain.run(
                {
                    "title": st.session_state.selected_title,
                    "tags": tags,
                    "wikipedia_research": wiki_research,
                }
            )
            st.write(script)