import os from langchain.document_loaders import PagedPDFSplitter from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Qdrant from langchain.document_loaders import TextLoader from langchain.chains.question_answering import load_qa_chain from langchain.llms import OpenAI import gradio as gr #keys and constants OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] api_key = os.environ["QDRANT_API_KEY"] host = "b6e7205d-c2b1-428f-bff4-e40de270387b.ap-northeast-1-0.aws.cloud.qdrant.io" embeddings = OpenAIEmbeddings() #load the document loader = PagedPDFSplitter("data/PNF.pdf") docs = loader.load_and_split() qdrant = Qdrant.from_documents( docs, embeddings, host=host, prefer_grpc=True, api_key=api_key ) print(docs[1]) # def question_answering(question): # chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff") # query = question # docs = qdrant.similarity_search(query) # answer = chain.run(input_documents=docs, question=query) # return answer # with gr.Blocks() as demo: # gr.Markdown("Start the typing below and then click **Run** to see the output.") # with gr.Row(): # inp = gr.Textbox(placeholder="Ask question here?") # out = gr.Textbox() # btn = gr.Button("Run") # btn.click(fn=question_answering, inputs=inp, outputs=out, api_name="search", queue=True) # demo.launch()