Spaces:
Build error
Build error
clementsan commited on
Commit ·
1ef8d7c
1
Parent(s): 2239106
Include ephemeral client and collection_name for chromadb
Browse files10 unmodified lines11121314151633 unmodified lines505152535455565758596086 unmodified lines14714814915015115215315415515615715815916016116248 unmodified lines21121221321421521653 unmodified lines27027127227327427527610 unmodified linesfrom langchain.memory import ConversationBufferMemoryfrom langchain.llms import HuggingFaceHubfrom transformers import AutoTokenizerimport transformersimport torch33 unmodified lines# Create vector databasedef create_db(splits):embedding = HuggingFaceEmbeddings()vectordb = Chroma.from_documents(documents=splits,embedding=embedding,# persist_directory=default_persist_directory)return vectordb86 unmodified lines# Create list of documents (when valid)#file_path = file_obj.namelist_file_path = [x.name for x in list_file_obj if x is not None]# print('list_file_path', list_file_path)progress(0.25, desc="Loading document...")# Load document and create splitsdoc_splits = load_doc(list_file_path, chunk_size, chunk_overlap)# Create or load Vector databaseprogress(0.5, desc="Generating vector database...")# global vector_dbvector_db = create_db(doc_splits)progress(0.9, desc="Done!")return vector_db, "Complete!"def initialize_LLM(llm_option, llm_temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):48 unmodified lineswith gr.Blocks(theme="base") as demo:vector_db = gr.State()qa_chain = gr.State()gr.Markdown("""<center><h2>PDF-based chatbot (powered by LangChain and open-source LLMs)</center></h2>53 unmodified lines#upload_btn.upload(upload_file, inputs=[upload_btn], outputs=[document])db_btn.click(initialize_database, \inputs=[document, slider_chunk_size, slider_chunk_overlap], \outputs=[vector_db, db_progress])qachain_btn.click(initialize_LLM, \inputs=[llm_btn, slider_temperature, slider_maxtokens, slider_topk, vector_db], \outputs=[qa_chain, llm_progress]).then(lambda:[None,"",0,"",0], \10 unmodified lines11121314151617181933 unmodified lines535455565758596061626364656686 unmodified lines15315415515615715815916016116216316416516616716816917048 unmodified lines21922022122222322422553 unmodified lines27928028128228328428510 unmodified linesfrom langchain.memory import ConversationBufferMemoryfrom langchain.llms import HuggingFaceHubfrom pathlib import Pathimport chromadbfrom transformers import AutoTokenizerimport transformersimport torch33 unmodified lines# Create vector databasedef create_db(splits, collection_name):embedding = HuggingFaceEmbeddings()new_client = chromadb.EphemeralClient()vectordb = Chroma.from_documents(documents=splits,embedding=embedding,client=new_client,collection_name=collection_name,# persist_directory=default_persist_directory)return vectordb86 unmodified lines# Create list of documents (when valid)#file_path = file_obj.namelist_file_path = [x.name for x in list_file_obj if x is not None]collection_name = Path(list_file_path[0]).stem# print('list_file_path: ', list_file_path)# print('Collection name: ', collection_name)progress(0.25, desc="Loading document...")# Load document and create splitsdoc_splits = load_doc(list_file_path, chunk_size, chunk_overlap)# Create or load Vector databaseprogress(0.5, desc="Generating vector database...")# global vector_dbvector_db = create_db(doc_splits, collection_name)progress(0.9, desc="Done!")return vector_db, collection_name, "Complete!"def initialize_LLM(llm_option, llm_temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):48 unmodified lineswith gr.Blocks(theme="base") as demo:vector_db = gr.State()qa_chain = gr.State()collection_name = gr.State()gr.Markdown("""<center><h2>PDF-based chatbot (powered by LangChain and open-source LLMs)</center></h2>53 unmodified lines#upload_btn.upload(upload_file, inputs=[upload_btn], outputs=[document])db_btn.click(initialize_database, \inputs=[document, slider_chunk_size, slider_chunk_overlap], \outputs=[vector_db, collection_name, db_progress])qachain_btn.click(initialize_LLM, \inputs=[llm_btn, slider_temperature, slider_maxtokens, slider_topk, vector_db], \outputs=[qa_chain, llm_progress]).then(lambda:[None,"",0,"",0], \
app.py+14-5