-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
57 lines (38 loc) · 1.85 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
from dotenv import load_dotenv
import streamlit as st
import google.generativeai as genai
from langchain_community.vectorstores import FAISS
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from config import process_pdf
load_dotenv(override=True)
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
def user_input(user_question):
embeddings = GoogleGenerativeAIEmbeddings(model = "models/embedding-001")
new_db = FAISS.load_local("faiss_index", embeddings,allow_dangerous_deserialization=True)
docs = new_db.similarity_search(user_question)
chain = process_pdf.get_conversational_chain()
response = chain(
{"input_documents":docs, "question": user_question}
, return_only_outputs=True)
print(response)
st.write("Reply: ", response["output_text"])
def main():
st.set_page_config("PDF Q&A Chatbot", page_icon = ":scroll:")
st.header("PDF📚 - Chat BOt 🤖 ")
user_question = st.text_input("Ask Question from the PDF Files uploaded .. ✍️📝")
if user_question:
user_input(user_question)
with st.sidebar:
st.image("logo.jpg")
st.write("---")
st.title("📁 PDF File's Section")
pdf_docs = st.file_uploader("Upload your PDF Files & \n Click on the Submit Button ", accept_multiple_files=True)
if st.button("Submit"):
with st.spinner("Processing..."): # user friendly message.
raw_text = process_pdf.get_pdf_text(pdf_docs) # get the pdf text
text_chunks = process_pdf.get_text_chunks(raw_text) # get the text chunks
process_pdf.get_vector_store(text_chunks) # create vector store
st.success("Done")
if __name__ == "__main__":
main()