Spaces:
Runtime error
Runtime error
update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from langchain.document_loaders import PyPDFLoader
|
|
10 |
from langchain.document_loaders import TextLoader
|
11 |
from langchain.document_loaders import Docx2txtLoader
|
12 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
|
|
13 |
import os
|
14 |
import tempfile
|
15 |
|
@@ -30,7 +31,7 @@ def conversation_chat(query, chain, history):
|
|
30 |
history.append((query, result["answer"]))
|
31 |
return result["answer"]
|
32 |
|
33 |
-
def display_chat_history():
|
34 |
reply_container = st.container()
|
35 |
container = st.container()
|
36 |
|
@@ -48,8 +49,8 @@ def display_chat_history():
|
|
48 |
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="thumbs")
|
49 |
message(st.session_state["generated"][i], key=str(i), avatar_style="fun-emoji")
|
50 |
|
51 |
-
def create_conversational_chain(vector_store
|
52 |
-
|
53 |
replicate_api_token = "r8_AA3K1fhDykqLa5M74E5V0w5ss1z0P9S3foWJl" # Replace with your actual token
|
54 |
os.environ["REPLICATE_API_TOKEN"] = replicate_api_token
|
55 |
|
@@ -97,14 +98,13 @@ def main():
|
|
97 |
text_splitter = CharacterTextSplitter(separator="\n", chunk_size=1000, chunk_overlap=100, length_function=len)
|
98 |
text_chunks = text_splitter.split_documents(text)
|
99 |
|
100 |
-
|
101 |
-
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", model_kwargs={'device': 'cpu'})
|
102 |
-
vector_store = FAISS.from_documents(text_chunks, embedding=embeddings)
|
103 |
-
|
104 |
-
# Create the chain object
|
105 |
-
chain = create_conversational_chain(vector_store, text_chunks)
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
main()
|
|
|
10 |
from langchain.document_loaders import TextLoader
|
11 |
from langchain.document_loaders import Docx2txtLoader
|
12 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
13 |
+
from dotenv import load_dotenv # Add this line for loading environment variables
|
14 |
import os
|
15 |
import tempfile
|
16 |
|
|
|
31 |
history.append((query, result["answer"]))
|
32 |
return result["answer"]
|
33 |
|
34 |
+
def display_chat_history(chain):
|
35 |
reply_container = st.container()
|
36 |
container = st.container()
|
37 |
|
|
|
49 |
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="thumbs")
|
50 |
message(st.session_state["generated"][i], key=str(i), avatar_style="fun-emoji")
|
51 |
|
52 |
+
def create_conversational_chain(vector_store):
|
53 |
+
load_dotenv()
|
54 |
replicate_api_token = "r8_AA3K1fhDykqLa5M74E5V0w5ss1z0P9S3foWJl" # Replace with your actual token
|
55 |
os.environ["REPLICATE_API_TOKEN"] = replicate_api_token
|
56 |
|
|
|
98 |
text_splitter = CharacterTextSplitter(separator="\n", chunk_size=1000, chunk_overlap=100, length_function=len)
|
99 |
text_chunks = text_splitter.split_documents(text)
|
100 |
|
101 |
+
st.write("Text chunks lengths:", [len(chunk) for chunk in text_chunks])
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2",
|
104 |
+
model_kwargs={'device': 'cpu'})
|
105 |
+
vector_store = FAISS.from_documents(text_chunks, embedding=embeddings)
|
106 |
+
chain = create_conversational_chain(vector_store)
|
107 |
+
display_chat_history(chain)
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
main()
|