bstraehle commited on
Commit
b07ca3a
·
1 Parent(s): 8cffc38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -30,7 +30,6 @@ MODEL_NAME = "gpt-4"
30
  def invoke(openai_api_key, youtube_url, process_video, prompt):
31
  openai.api_key = openai_api_key
32
  if (process_video):
33
- print(111)
34
  loader = GenericLoader(YoutubeAudioLoader([youtube_url], YOUTUBE_DIR), OpenAIWhisperParser())
35
  docs = loader.load()
36
  shutil.rmtree(YOUTUBE_DIR)
@@ -38,16 +37,16 @@ def invoke(openai_api_key, youtube_url, process_video, prompt):
38
  splits = text_splitter.split_documents(docs)
39
  vector_db = Chroma.from_documents(documents = splits, embedding = OpenAIEmbeddings(), persist_directory = CHROMA_DIR)
40
  else:
41
- print(222)
42
  vector_db = Chroma(persist_directory = CHROMA_DIR, embedding_function = OpenAIEmbeddings())
43
  llm = ChatOpenAI(model_name = MODEL_NAME, temperature = 0)
44
  qa_chain = RetrievalQA.from_chain_type(llm, retriever = vector_db.as_retriever(), return_source_documents = True, chain_type_kwargs = {"prompt": QA_CHAIN_PROMPT})
45
  result = qa_chain({"query": prompt})
46
- #shutil.rmtree(CHROMA_DIR)
47
  return result["result"]
48
 
49
- description = """The app demonstrates how to use a <strong>Large Language Model</strong> (LLM) with <strong>Retrieval Augmented Generation</strong> (RAG) on external data.
50
- Enter an OpenAI API key, YouTube URL (external data), and prompt to perform semantic search, sentiment analysis, summarization, translation, etc.\n\n
 
 
51
  Implementation: <a href='https://www.gradio.app/'>Gradio</a> UI using <a href='https://platform.openai.com/'>OpenAI</a> API
52
  via AI-first <a href='https://www.langchain.com/'>LangChain</a> toolkit with <a href='https://openai.com/research/whisper'>Whisper</a> (speech to text)
53
  and <a href='https://openai.com/research/gpt-4'>GPT-4</a> (LLM use cases) foundation models as well as AI-native
 
30
  def invoke(openai_api_key, youtube_url, process_video, prompt):
31
  openai.api_key = openai_api_key
32
  if (process_video):
 
33
  loader = GenericLoader(YoutubeAudioLoader([youtube_url], YOUTUBE_DIR), OpenAIWhisperParser())
34
  docs = loader.load()
35
  shutil.rmtree(YOUTUBE_DIR)
 
37
  splits = text_splitter.split_documents(docs)
38
  vector_db = Chroma.from_documents(documents = splits, embedding = OpenAIEmbeddings(), persist_directory = CHROMA_DIR)
39
  else:
 
40
  vector_db = Chroma(persist_directory = CHROMA_DIR, embedding_function = OpenAIEmbeddings())
41
  llm = ChatOpenAI(model_name = MODEL_NAME, temperature = 0)
42
  qa_chain = RetrievalQA.from_chain_type(llm, retriever = vector_db.as_retriever(), return_source_documents = True, chain_type_kwargs = {"prompt": QA_CHAIN_PROMPT})
43
  result = qa_chain({"query": prompt})
 
44
  return result["result"]
45
 
46
+ description = """The app demonstrates how to use a <strong>Large Language Model</strong> (LLM) with <strong>Retrieval Augmented Generation</strong> (RAG) on external data.\n\n
47
+ Usage: Enter an OpenAI API key, YouTube URL (external data), and prompt to perform semantic search, sentiment analysis, summarization, translation, etc.
48
+ "Process Video" specifies whether or not to perform speech to text processing. To ask multiple question related to the same video, typically set it to "True"
49
+ the first time, and then set it to "False". Note that persistence is not guaranteed in the Hugging Face free tier (I plan to migrate to AWS S3).\n\n
50
  Implementation: <a href='https://www.gradio.app/'>Gradio</a> UI using <a href='https://platform.openai.com/'>OpenAI</a> API
51
  via AI-first <a href='https://www.langchain.com/'>LangChain</a> toolkit with <a href='https://openai.com/research/whisper'>Whisper</a> (speech to text)
52
  and <a href='https://openai.com/research/gpt-4'>GPT-4</a> (LLM use cases) foundation models as well as AI-native