Noobian commited on
Commit
61534eb
1 Parent(s): 5c3fb14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -11,7 +11,6 @@ from langchain.indexes import VectorstoreIndexCreator
11
  from langchain import OpenAI, VectorDBQA
12
 
13
  import os
14
- openai_api_key = os.environ["OPENAI_API_KEY"]
15
 
16
 
17
  def pdf_to_text(pdf_file, query):
@@ -40,15 +39,13 @@ def pdf_to_text(pdf_file, query):
40
  llm = HuggingFaceHub(repo_id="google/flan-t5-xl", model_kwargs={"temperature":0, "max_length":512})
41
  loaders = UnstructuredPDFLoader(pdf_file)
42
 
43
- index = VectorstoreIndexCreator(
44
- embedding=HuggingFaceEmbeddings(),
45
- text_splitter= CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).from_loaders(loaders))
46
  #inference
47
  qa = VectorDBQA.from_chain_type(llm=llm, chain_type="stuff", vectorstore=vectorstore)
48
  from langchain.chains import RetrievalQA
49
  chain = RetrievalQA.from_chain_type(llm=llm,
50
  chain_type="stuff",
51
- retriever=index.vectorstore.as_retriever(),
52
  input_key="question")
53
  return chain.run(query)
54
 
 
11
  from langchain import OpenAI, VectorDBQA
12
 
13
  import os
 
14
 
15
 
16
  def pdf_to_text(pdf_file, query):
 
39
  llm = HuggingFaceHub(repo_id="google/flan-t5-xl", model_kwargs={"temperature":0, "max_length":512})
40
  loaders = UnstructuredPDFLoader(pdf_file)
41
 
42
+ index = vectorstore.as_retriever()
 
 
43
  #inference
44
  qa = VectorDBQA.from_chain_type(llm=llm, chain_type="stuff", vectorstore=vectorstore)
45
  from langchain.chains import RetrievalQA
46
  chain = RetrievalQA.from_chain_type(llm=llm,
47
  chain_type="stuff",
48
+ retriever=index,
49
  input_key="question")
50
  return chain.run(query)
51