Spaces:
Sleeping
Sleeping
Mr-Vicky-01
commited on
Commit
•
b369983
1
Parent(s):
1d758a2
Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,11 @@ from langchain.vectorstores import FAISS
|
|
8 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
9 |
from langchain.chains.question_answering import load_qa_chain
|
10 |
from langchain.prompts import PromptTemplate
|
|
|
11 |
from dotenv import load_dotenv
|
12 |
|
13 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
14 |
|
15 |
-
|
16 |
def get_pdf_text(pdf_docs):
|
17 |
text = ""
|
18 |
for pdf in pdf_docs:
|
@@ -53,6 +53,11 @@ def user_input(user_question):
|
|
53 |
response = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
|
54 |
return response["output_text"]
|
55 |
|
|
|
|
|
|
|
|
|
|
|
56 |
# Streamlit app initialization
|
57 |
st.title("Chat With PDF 📄")
|
58 |
|
@@ -72,7 +77,8 @@ with st.sidebar:
|
|
72 |
user_prompt = st.chat_input("Ask me anything about the content of the PDF:")
|
73 |
if user_prompt:
|
74 |
st.session_state.messages.append({'role': 'user', "content": user_prompt})
|
75 |
-
|
|
|
76 |
st.session_state.messages.append({'role': 'assistant', "content": response})
|
77 |
|
78 |
for message in st.session_state.messages:
|
|
|
8 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
9 |
from langchain.chains.question_answering import load_qa_chain
|
10 |
from langchain.prompts import PromptTemplate
|
11 |
+
import time
|
12 |
from dotenv import load_dotenv
|
13 |
|
14 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
15 |
|
|
|
16 |
def get_pdf_text(pdf_docs):
|
17 |
text = ""
|
18 |
for pdf in pdf_docs:
|
|
|
53 |
response = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
|
54 |
return response["output_text"]
|
55 |
|
56 |
+
def response_generator(response):
|
57 |
+
for word in response.split():
|
58 |
+
yield word + " "
|
59 |
+
time.sleep(0.05)
|
60 |
+
|
61 |
# Streamlit app initialization
|
62 |
st.title("Chat With PDF 📄")
|
63 |
|
|
|
77 |
user_prompt = st.chat_input("Ask me anything about the content of the PDF:")
|
78 |
if user_prompt:
|
79 |
st.session_state.messages.append({'role': 'user', "content": user_prompt})
|
80 |
+
answer = user_input(user_prompt)
|
81 |
+
response = response_generator(response=answer)
|
82 |
st.session_state.messages.append({'role': 'assistant', "content": response})
|
83 |
|
84 |
for message in st.session_state.messages:
|