Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,54 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from langchain.prompts import PromptTemplate
|
| 4 |
-
from langchain.chains import LLMChain
|
| 5 |
from langchain.memory import ConversationBufferMemory
|
| 6 |
from langchain.utilities import WikipediaAPIWrapper
|
| 7 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 8 |
|
|
|
|
| 9 |
# Load the GPT-2 model and tokenizer
|
| 10 |
model_name = "gpt2"
|
| 11 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
# app framework
|
| 16 |
st.title('Youtube Content Studio 🚀')
|
| 17 |
-
prompt=st.text_input('Plug in your prompt here')
|
| 18 |
|
| 19 |
-
#Prompt templates
|
| 20 |
-
title_template=PromptTemplate(
|
| 21 |
input_variables=['topic'],
|
| 22 |
template='write me a youtube video title about {topic}'
|
| 23 |
)
|
| 24 |
-
script_template=PromptTemplate(
|
| 25 |
-
input_variables=['title','wikipedia_research'],
|
| 26 |
template='write me a youtube script based on this title TITLE: {title} while leveraging this wikipedia research: {wikipedia_research}'
|
| 27 |
)
|
| 28 |
|
| 29 |
# Memory
|
| 30 |
-
title_memory=ConversationBufferMemory(input_key='topic',memory_key='chat_history')
|
| 31 |
-
script_memory=ConversationBufferMemory(input_key='title',memory_key='chat_history')
|
|
|
|
| 32 |
# LLMS
|
| 33 |
-
llm=
|
| 34 |
-
title_chain=LLMChain(llm=llm,prompt=title_template,verbose=True,output_key='title',memory=title_memory)
|
| 35 |
-
script_chain=LLMChain(llm=llm,prompt=script_template,verbose=True,output_key='script',memory=script_memory)
|
| 36 |
|
| 37 |
-
wiki=WikipediaAPIWrapper()
|
| 38 |
|
| 39 |
# Show stuff to the screen if there is a prompt
|
| 40 |
if prompt:
|
| 41 |
-
title=title_chain.run(prompt)
|
| 42 |
-
wiki_research=wiki.run(prompt)
|
| 43 |
-
script=script_chain.run(title=title,wikipedia_research=wiki_research)
|
| 44 |
st.write(title)
|
| 45 |
st.write(script)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
with st.expander('Title History'):
|
| 49 |
st.info(title_memory.buffer)
|
| 50 |
with st.expander('Script History'):
|
| 51 |
-
st.info(script_memory.buffer)
|
| 52 |
with st.expander('Wikipedia research History'):
|
| 53 |
-
st.info(wiki_research)
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from langchain.prompts import PromptTemplate
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
from langchain.memory import ConversationBufferMemory
|
| 6 |
from langchain.utilities import WikipediaAPIWrapper
|
| 7 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 8 |
|
| 9 |
+
|
| 10 |
# Load the GPT-2 model and tokenizer
|
| 11 |
model_name = "gpt2"
|
| 12 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 13 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
|
|
|
| 14 |
|
| 15 |
# app framework
|
| 16 |
st.title('Youtube Content Studio 🚀')
|
| 17 |
+
prompt = st.text_input('Plug in your prompt here')
|
| 18 |
|
| 19 |
+
# Prompt templates
|
| 20 |
+
title_template = PromptTemplate(
|
| 21 |
input_variables=['topic'],
|
| 22 |
template='write me a youtube video title about {topic}'
|
| 23 |
)
|
| 24 |
+
script_template = PromptTemplate(
|
| 25 |
+
input_variables=['title', 'wikipedia_research'],
|
| 26 |
template='write me a youtube script based on this title TITLE: {title} while leveraging this wikipedia research: {wikipedia_research}'
|
| 27 |
)
|
| 28 |
|
| 29 |
# Memory
|
| 30 |
+
title_memory = ConversationBufferMemory(input_key='topic', memory_key='chat_history')
|
| 31 |
+
script_memory = ConversationBufferMemory(input_key='title', memory_key='chat_history')
|
| 32 |
+
|
| 33 |
# LLMS
|
| 34 |
+
llm = model
|
| 35 |
+
title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True, output_key='title', memory=title_memory)
|
| 36 |
+
script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True, output_key='script', memory=script_memory)
|
| 37 |
|
| 38 |
+
wiki = WikipediaAPIWrapper()
|
| 39 |
|
| 40 |
# Show stuff to the screen if there is a prompt
|
| 41 |
if prompt:
|
| 42 |
+
title = title_chain.run(prompt)
|
| 43 |
+
wiki_research = wiki.run(prompt)
|
| 44 |
+
script = script_chain.run(title=title, wikipedia_research=wiki_research)
|
| 45 |
st.write(title)
|
| 46 |
st.write(script)
|
| 47 |
+
|
|
|
|
| 48 |
with st.expander('Title History'):
|
| 49 |
st.info(title_memory.buffer)
|
| 50 |
with st.expander('Script History'):
|
| 51 |
+
st.info(script_memory.buffer)
|
| 52 |
with st.expander('Wikipedia research History'):
|
| 53 |
+
st.info(wiki_research)
|
| 54 |
+
|