bstraehle commited on
Commit
28cd58f
·
1 Parent(s): e9e1421

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -4
app.py CHANGED
@@ -22,11 +22,9 @@ template = """Use the following pieces of context to answer the question at the
22
 
23
  QA_CHAIN_PROMPT = PromptTemplate(input_variables = ["context", "question"], template = template)
24
 
25
- is_initial_load = True
26
-
27
  def invoke(openai_api_key, youtube_url, prompt):
28
  openai.api_key = openai_api_key
29
- if is_initial_load:
30
  youtube_dir = "docs/youtube/"
31
  loader = GenericLoader(YoutubeAudioLoader([youtube_url], youtube_dir), OpenAIWhisperParser())
32
  docs = loader.load()
@@ -36,7 +34,6 @@ def invoke(openai_api_key, youtube_url, prompt):
36
  vectordb = Chroma.from_documents(documents = splits, embedding = OpenAIEmbeddings(), persist_directory = chroma_dir)
37
  llm = ChatOpenAI(model_name = "gpt-4", temperature = 0)
38
  qa_chain = RetrievalQA.from_chain_type(llm, retriever = vectordb.as_retriever(), return_source_documents = True, chain_type_kwargs = {"prompt": QA_CHAIN_PROMPT})
39
- is_initial_load = False
40
  result = qa_chain({"query": prompt})
41
  #shutil.rmtree(youtube_dir)
42
  #shutil.rmtree(chroma_dir)
 
22
 
23
  QA_CHAIN_PROMPT = PromptTemplate(input_variables = ["context", "question"], template = template)
24
 
 
 
25
  def invoke(openai_api_key, youtube_url, prompt):
26
  openai.api_key = openai_api_key
27
+ if vectordb is not None:
28
  youtube_dir = "docs/youtube/"
29
  loader = GenericLoader(YoutubeAudioLoader([youtube_url], youtube_dir), OpenAIWhisperParser())
30
  docs = loader.load()
 
34
  vectordb = Chroma.from_documents(documents = splits, embedding = OpenAIEmbeddings(), persist_directory = chroma_dir)
35
  llm = ChatOpenAI(model_name = "gpt-4", temperature = 0)
36
  qa_chain = RetrievalQA.from_chain_type(llm, retriever = vectordb.as_retriever(), return_source_documents = True, chain_type_kwargs = {"prompt": QA_CHAIN_PROMPT})
 
37
  result = qa_chain({"query": prompt})
38
  #shutil.rmtree(youtube_dir)
39
  #shutil.rmtree(chroma_dir)