DEV Community

Discussion on: Chat with your CSV: Visualize Your Data with Langchain and Streamlit

Collapse
 
ngonidzashe profile image
Ngonidzashe Nzenze

You could make use of the UnstructuredPDFLoader and the load_qa_chain as follows:

from langchain.document_loaders import UnstructuredPDFLoader
from langchain.llms import OpenAI
from langchain.chains.question_answering import load_qa_chain

API_KEY = 'api-key'

loader = UnstructuredPDFLoader("your_document.pdf")
data = loader.load()

chain = load_qa_chain(
    OpenAI(temperature=0.9, openai_api_key=API_KEY), chain_type="stuff"
)

# model response
response = chain.run(input_documents=data, question="<Input your query here>")

Enter fullscreen mode Exit fullscreen mode

You can get more information here