Spaces:
Build error
Build error
Update app.py
Browse files19 unmodified lines20212223242324252624 unmodified lines51525354555657585657585916 unmodified lines767778818283848586878889909192939495969798991001011021031047980818256 unmodified lines13914014116714214314414528 unmodified lines17417517620220320420520620717717817918019 unmodified linesimport tqdm import accelerate
default_persist_directory = './chromaDB/'default_persist_directory = './ChromaDB'
llm_name0 = "mistralai/Mixtral-8x7B-Instruct-v0.1"
24 unmodified lines vectordb = Chroma.from_documents( documents=splits, embedding=embedding, persist_directory="./chroma_db", client=new_client, collection_name=collection_name, persist_directory=default_persist_directory ) collection_name=collection_name) return vectordb
16 unmodified lines llm = HuggingFaceHub( repo_id=llm_model, model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "load_in_8bit": True} ) elif llm_model == "microsoft/phi-2": raise gr.Error("phi-2 model requires 'trust_remote_code=True', currently not supported by langchain HuggingFaceHub...") llm = HuggingFaceHub( repo_id=llm_model, model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "trust_remote_code": True, "torch_dtype": "auto"} ) elif llm_model == "TinyLlama/TinyLlama-1.1B-Chat-v1.0": llm = HuggingFaceHub( repo_id=llm_model, model_kwargs={"temperature": temperature, "max_new_tokens": 250, "top_k": top_k} ) elif llm_model == "meta-llama/Llama-2-7b-chat-hf": raise gr.Error("Llama-2-7b-chat-hf model requires a Pro subscription...") llm = HuggingFaceHub( repo_id=llm_model, model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k} ) else: llm = HuggingFaceHub( repo_id=llm_model, # model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "trust_remote_code": True, "torch_dtype": "auto"} model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k} ) ) progress(0.75, desc="Defining buffer memory...") memory = ConversationBufferMemory(56 unmodified linesdef conversation(qa_chain, message, history): formatted_chat_history = format_chat_history(message, history) #print("formatted_chat_history",formatted_chat_history) formatted_chat_history = "" # Generate response using QA chain response = qa_chain({"question": message, "chat_history": formatted_chat_history}) response_answer = response["answer"]28 unmodified lines collection_name = gr.State() gr.Markdown( """<center><h2>PDF-based chatbot (powered by LangChain and open-source LLMs)</center></h2> <h3>Ask any questions about your PDF documents, along with follow-ups</h3> <b>Note:</b> This AI assistant performs retrieval-augmented generation from your PDF documents. \ When generating answers, it takes past questions into account (via conversational memory), and includes document references for clarity purposes.</i> <br><b>Warning:</b> This space uses the free CPU Basic hardware from Hugging Face. Some steps and LLM models used below (free inference endpoints) can take some time to generate an output.<br> """) """<center><h2>ChatPDF</center></h2>""") with gr.Tab("Step 1 - Document pre-processing"): with gr.Row(): document = gr.Files(height=100, file_count="multiple", file_types=["pdf"], interactive=True, label="Upload your PDF documents (single or multiple)")app.py+6-36