Spaces:
Sleeping
Sleeping
sankar12345
commited on
Commit
•
84e3b2a
1
Parent(s):
80cbdea
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
3 |
from dotenv import load_dotenv
|
4 |
from PyPDF2 import PdfReader
|
@@ -33,14 +32,14 @@ def get_text_chunks(text):
|
|
33 |
|
34 |
def get_vectorstore(text_chunks):
|
35 |
# embeddings = OpenAIEmbeddings()
|
36 |
-
embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl"
|
37 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
38 |
return vectorstore
|
39 |
|
40 |
|
41 |
def get_conversation_chain(vectorstore):
|
42 |
# llm = ChatOpenAI()
|
43 |
-
llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512}
|
44 |
|
45 |
memory = ConversationBufferMemory(
|
46 |
memory_key='chat_history', return_messages=True)
|
@@ -53,13 +52,7 @@ def get_conversation_chain(vectorstore):
|
|
53 |
|
54 |
|
55 |
def handle_userinput(user_question):
|
56 |
-
|
57 |
-
if conversation is None:
|
58 |
-
st.error("Conversation not initialized. Please upload PDFs and process them.")
|
59 |
-
return
|
60 |
-
|
61 |
-
print("Conversation:", conversation) # Add this line for debugging
|
62 |
-
response = conversation({'question': user_question})
|
63 |
st.session_state.chat_history = response['chat_history']
|
64 |
|
65 |
for i, message in enumerate(st.session_state.chat_history):
|
@@ -71,8 +64,6 @@ def handle_userinput(user_question):
|
|
71 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
72 |
|
73 |
|
74 |
-
|
75 |
-
|
76 |
def main():
|
77 |
load_dotenv()
|
78 |
st.set_page_config(page_title="Chat with multiple PDFs",
|
@@ -110,4 +101,4 @@ def main():
|
|
110 |
|
111 |
|
112 |
if __name__ == '__main__':
|
113 |
-
main()
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from dotenv import load_dotenv
|
3 |
from PyPDF2 import PdfReader
|
|
|
32 |
|
33 |
def get_vectorstore(text_chunks):
|
34 |
# embeddings = OpenAIEmbeddings()
|
35 |
+
embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
|
36 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
37 |
return vectorstore
|
38 |
|
39 |
|
40 |
def get_conversation_chain(vectorstore):
|
41 |
# llm = ChatOpenAI()
|
42 |
+
llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512})
|
43 |
|
44 |
memory = ConversationBufferMemory(
|
45 |
memory_key='chat_history', return_messages=True)
|
|
|
52 |
|
53 |
|
54 |
def handle_userinput(user_question):
|
55 |
+
response = st.session_state.conversation({'question': user_question})
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
st.session_state.chat_history = response['chat_history']
|
57 |
|
58 |
for i, message in enumerate(st.session_state.chat_history):
|
|
|
64 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
65 |
|
66 |
|
|
|
|
|
67 |
def main():
|
68 |
load_dotenv()
|
69 |
st.set_page_config(page_title="Chat with multiple PDFs",
|
|
|
101 |
|
102 |
|
103 |
if __name__ == '__main__':
|
104 |
+
main()
|