nirmalaag commited on
Commit
05de07f
·
verified ·
1 Parent(s): 1fc064e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -15,6 +15,7 @@ from langchain.document_loaders.pdf import PyMuPDFLoader
15
  import os
16
  #import fitz
17
  #import tempfile
 
18
 
19
  img = Image.open('image/nexio_logo1.png')
20
  st.set_page_config(page_title="PDF Chatbot App",page_icon=img,layout="centered")
@@ -59,21 +60,26 @@ def main():
59
 
60
  # Accept user question
61
  query = st.text_input("Ask questions about your PDF file:")
62
-
63
  if query:
64
 
65
  #PATH = 'model/'
66
  #llm = AutoModelForCausalLM.from_pretrained("CohereForAI/aya-101")
67
  # llm = AutoModelForCausalLM.from_pretrained(PATH,local_files_only=True)
68
  llm = huggingface_hub.HuggingFaceHub(repo_id="google/flan-t5-small",
69
- model_kwargs={"temperature":1.0, "max_length":500})
70
- docs = vector_store.similarity_search(query=query, k=3)
71
- st.write(docs)
72
- chain = load_qa_chain(llm=llm, chain_type="stuff")
73
- response = chain.run(input_documents=docs, question=query)
74
- #retriever=vector_store.as_retriever()
75
- #chain = RetrievalQA.from_chain_type(llm=llm,chain_type="stuff",retriever=retriever)
76
- #response = chain.run(chain)
 
 
 
 
 
77
  st.write(response)
78
 
79
 
 
15
  import os
16
  #import fitz
17
  #import tempfile
18
+ from langchain.chains.summarize import load_summarize_chain
19
 
20
  img = Image.open('image/nexio_logo1.png')
21
  st.set_page_config(page_title="PDF Chatbot App",page_icon=img,layout="centered")
 
60
 
61
  # Accept user question
62
  query = st.text_input("Ask questions about your PDF file:")
63
+
64
  if query:
65
 
66
  #PATH = 'model/'
67
  #llm = AutoModelForCausalLM.from_pretrained("CohereForAI/aya-101")
68
  # llm = AutoModelForCausalLM.from_pretrained(PATH,local_files_only=True)
69
  llm = huggingface_hub.HuggingFaceHub(repo_id="google/flan-t5-small",
70
+ model_kwargs={"temperature":1.0, "max_length":256})
71
+ if query == 'Summarize':
72
+ docs = pdf_reader.load_and_split()
73
+ chain = load_summarize_chain(llm, chain_type="map_reduce")
74
+ response = chain.run(docs)
75
+ else:
76
+ docs = vector_store.similarity_search(query=query, k=2)
77
+ #st.write(docs)
78
+ chain = load_qa_chain(llm=llm, chain_type="stuff")
79
+ response = chain.run(input_documents=docs, question=query)
80
+ #retriever=vector_store.as_retriever()
81
+ #chain = RetrievalQA.from_chain_type(llm=llm,chain_type="stuff",retriever=retriever)
82
+ #response = chain.run(chain)
83
  st.write(response)
84
 
85