import gradio as gr from langchain.text_splitter import CharacterTextSplitter from langchain.llms import HuggingFaceHub from langchain.embeddings import HuggingFaceEmbeddings from langchain.vectorstores import Chroma from langchain.chains import RetrievalQA from langchain.document_loaders import PyMuPDFLoader import os os.environ["HUGGINGFACEHUB_API_TOKEN"] = "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" def load_doc(pdf_doc): loader = PyMuPDFLoader(pdf_doc.name) documents = loader.load() embedding = HuggingFaceEmbeddings() text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=100) text = text_splitter.split_documents(documents) db = Chroma.from_documents(text, embedding) llm = HuggingFaceHub(repo_id="OpenAssistant/oasst-sft-1-pythia-12b", model_kwargs={"temperature": 1.0, "max_length": 512}) global chain chain = RetrievalQA.from_chain_type(llm=llm,chain_type="stuff",retriever=db.as_retriever()) return 'Document has successfully been loaded' def answer_query(query): question = query return chain.run(question) html = """
Upload a PDF File, then click on Load PDF File
Once the document has been loaded you can begin chatting with the PDF =)