Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,10 +44,14 @@ from langchain_community.document_loaders import PDFMinerLoader
|
|
44 |
from langchain_text_splitters import NLTKTextSplitter
|
45 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
46 |
from langchain_community.vectorstores import Chroma
|
|
|
|
|
|
|
47 |
|
48 |
uploaded_file = st.file_uploader("Choose a pdf file",type = "pdf")
|
49 |
|
50 |
if uploaded_file is not None:
|
|
|
51 |
pdf_file = io.BytesIO(uploaded_file.read())
|
52 |
pdf_loader = PDFMinerLoader(pdf_file)
|
53 |
dat_nik = pdf_loader.load()
|
@@ -63,6 +67,24 @@ if uploaded_file is not None:
|
|
63 |
db_connection = Chroma(persist_directory="./chroma_db_", embedding_function=embedding_model)
|
64 |
|
65 |
retriever = db_connection.as_retriever(search_kwargs={"k": 5})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# dat = PDFMinerLoader("2404.07143.pdf")
|
68 |
# dat_nik =dat.load()
|
@@ -86,23 +108,5 @@ if uploaded_file is not None:
|
|
86 |
|
87 |
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
def format_docs(docs):
|
92 |
-
return "\n\n".join(doc.page_content for doc in docs)
|
93 |
-
|
94 |
-
# format chunks: takes the 5 results, combines all the chunks and displays one output.
|
95 |
-
rag_chain = (
|
96 |
-
{"context": retriever | format_docs, "question": RunnablePassthrough()}
|
97 |
-
| chat_template
|
98 |
-
| chat_model
|
99 |
-
| output_parser
|
100 |
-
)
|
101 |
|
102 |
-
user_input = st.text_area("Ask Questions to AI")
|
103 |
-
if st.button("Submit"):
|
104 |
-
st.subheader(":green[Query:]")
|
105 |
-
st.subheader(user_input)
|
106 |
-
response = rag_chain.invoke(user_input)
|
107 |
-
st.subheader(":green[Response:-]")
|
108 |
-
st.write(response)
|
|
|
44 |
from langchain_text_splitters import NLTKTextSplitter
|
45 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
46 |
from langchain_community.vectorstores import Chroma
|
47 |
+
from langchain_core.runnables import RunnablePassthrough
|
48 |
+
|
49 |
+
|
50 |
|
51 |
uploaded_file = st.file_uploader("Choose a pdf file",type = "pdf")
|
52 |
|
53 |
if uploaded_file is not None:
|
54 |
+
|
55 |
pdf_file = io.BytesIO(uploaded_file.read())
|
56 |
pdf_loader = PDFMinerLoader(pdf_file)
|
57 |
dat_nik = pdf_loader.load()
|
|
|
67 |
db_connection = Chroma(persist_directory="./chroma_db_", embedding_function=embedding_model)
|
68 |
|
69 |
retriever = db_connection.as_retriever(search_kwargs={"k": 5})
|
70 |
+
|
71 |
+
def format_docs(docs):
|
72 |
+
return "\n\n".join(doc.page_content for doc in docs)
|
73 |
+
|
74 |
+
rag_chain = (
|
75 |
+
{"context": retriever | format_docs, "question": RunnablePassthrough()}
|
76 |
+
| chat_template
|
77 |
+
| chat_model
|
78 |
+
| output_parser
|
79 |
+
)
|
80 |
+
|
81 |
+
user_input = st.text_area("Ask Questions to AI")
|
82 |
+
if st.button("Submit"):
|
83 |
+
st.subheader(":green[Query:]")
|
84 |
+
st.subheader(user_input)
|
85 |
+
response = rag_chain.invoke(user_input)
|
86 |
+
st.subheader(":green[Response:-]")
|
87 |
+
st.write(response)
|
88 |
|
89 |
# dat = PDFMinerLoader("2404.07143.pdf")
|
90 |
# dat_nik =dat.load()
|
|
|
108 |
|
109 |
|
110 |
|
111 |
+
#takes user's question.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|