Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from langchain_community.document_loaders import PyPDFLoader
|
| 4 |
-
from
|
| 5 |
-
from langchain_community.vectorstores import Chroma
|
| 6 |
-
from langchain.chains import ConversationalRetrievalChain
|
| 7 |
-
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 8 |
-
from langchain_community.llms import HuggingFacePipeline, HuggingFaceHub
|
| 9 |
-
from langchain.chains import ConversationChain
|
| 10 |
from langchain.memory import ConversationBufferMemory
|
| 11 |
from pathlib import Path
|
| 12 |
import chromadb
|
|
@@ -16,25 +16,29 @@ import torch
|
|
| 16 |
import tqdm
|
| 17 |
import accelerate
|
| 18 |
|
| 19 |
-
#
|
| 20 |
chosen_llm_model = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 21 |
-
|
| 22 |
-
# Default chunk size and overlap
|
| 23 |
-
chunk_size = 600
|
| 24 |
-
chunk_overlap = 40
|
| 25 |
-
|
| 26 |
-
# Default model configuration
|
| 27 |
llm_temperature = 0.7
|
| 28 |
max_tokens = 1024
|
| 29 |
top_k = 3
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Initialize vector database in background
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
# Define functions (no changes needed here)
|
| 37 |
-
# ... (your existing functions here)
|
| 38 |
|
| 39 |
def demo():
|
| 40 |
with gr.Blocks(theme="base") as demo:
|
|
@@ -87,9 +91,4 @@ def demo():
|
|
| 87 |
# Chatbot events
|
| 88 |
msg.submit(conversation, inputs=[qa_chain, msg, chatbot])
|
| 89 |
submit_btn.click(conversation, inputs=[qa_chain, msg, chatbot])
|
| 90 |
-
clear_btn.click(lambda: [None, "", 0, "", 0, "", 0], inputs=None, outputs=[chatbot, doc_source1, source1_page, doc_source2,
|
| 91 |
-
|
| 92 |
-
demo.launch(debug=True)
|
| 93 |
-
|
| 94 |
-
if __name__ == "__main__":
|
| 95 |
-
demo()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from langchain_community.document_loaders import PyPDFLoader # Corrected import
|
| 4 |
+
from langchain_community.text_splitter import RecursiveCharacterTextSplitter # Corrected import
|
| 5 |
+
from langchain_community.vectorstores import Chroma # Corrected import
|
| 6 |
+
from langchain.chains import ConversationalRetrievalChain # Note: Not from "langchain_community"
|
| 7 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings # Corrected import
|
| 8 |
+
from langchain_community.llms import HuggingFacePipeline, HuggingFaceHub # Corrected import
|
| 9 |
+
from langchain.chains import ConversationChain # Note: Not from "langchain_community"
|
| 10 |
from langchain.memory import ConversationBufferMemory
|
| 11 |
from pathlib import Path
|
| 12 |
import chromadb
|
|
|
|
| 16 |
import tqdm
|
| 17 |
import accelerate
|
| 18 |
|
| 19 |
+
# LLM model and parameters (adjusted for clarity)
|
| 20 |
chosen_llm_model = "mistralai/Mistral-7B-Instruct-v0.2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
llm_temperature = 0.7
|
| 22 |
max_tokens = 1024
|
| 23 |
top_k = 3
|
| 24 |
|
| 25 |
+
# Chunk size and overlap (adjusted for clarity)
|
| 26 |
+
chunk_size = 600
|
| 27 |
+
chunk_overlap = 40
|
| 28 |
+
|
| 29 |
# Initialize vector database in background
|
| 30 |
+
accelerated(initialize_database)() # Function definition moved here
|
| 31 |
+
|
| 32 |
|
| 33 |
+
def initialize_database():
|
| 34 |
+
"""
|
| 35 |
+
This function initializes the vector database (assumed to be ChromaDB).
|
| 36 |
+
Modify this function based on your specific database needs.
|
| 37 |
+
"""
|
| 38 |
+
# Replace with your ChromaDB connection and schema creation logic
|
| 39 |
+
# ...
|
| 40 |
+
pass
|
| 41 |
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def demo():
|
| 44 |
with gr.Blocks(theme="base") as demo:
|
|
|
|
| 91 |
# Chatbot events
|
| 92 |
msg.submit(conversation, inputs=[qa_chain, msg, chatbot])
|
| 93 |
submit_btn.click(conversation, inputs=[qa_chain, msg, chatbot])
|
| 94 |
+
clear_btn.click(lambda: [None, "", 0, "", 0, "", 0], inputs=None, outputs=[chatbot, doc_source1, source1_page, doc_source2, source2_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|