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 lines11121314151617181933 unmodified lines53545553565758596061626364656686 unmodified lines15315415515615015715815916016116216316415716516615916716816917048 unmodified lines21922022122222322422553 unmodified lines27928028127328228328428510 unmodified linesfrom langchain.memory import ConversationBufferMemoryfrom langchain.llms import HuggingFaceHub
from pathlib import Pathimport chromadb
from transformers import AutoTokenizerimport transformersimport torch33 unmodified lines
# Create vector databasedef create_db(splits):def 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.name list_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('list_file_path: ', list_file_path) # print('Collection name: ', collection_name) progress(0.25, desc="Loading document...") # Load document and create splits doc_splits = load_doc(list_file_path, chunk_size, chunk_overlap) # Create or load Vector database progress(0.5, desc="Generating vector database...") # global vector_db vector_db = create_db(doc_splits) vector_db = create_db(doc_splits, collection_name) progress(0.9, desc="Done!") return vector_db, "Complete!" return vector_db, collection_name, "Complete!"
def initialize_LLM(llm_option, llm_temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):48 unmodified lines with 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, db_progress]) 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