File size: 1,453 Bytes
fddd959
636c987
fddd959
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04c03db
fddd959
 
04c03db
 
 
 
 
 
fddd959
 
04c03db
 
 
 
 
 
 
fddd959
04c03db
fddd959
 
636c987
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()