Spaces:
Sleeping
Sleeping
Chandranshu Jain
commited on
Commit
•
f942880
1
Parent(s):
0d5b48e
Update app.py
Browse files
app.py
CHANGED
@@ -33,20 +33,20 @@ def get_pdf(pdf_docs):
|
|
33 |
return text
|
34 |
|
35 |
def text_splitter(text):
|
36 |
-
|
37 |
# Set a really small chunk size, just to show.
|
38 |
chunk_size=500,
|
39 |
chunk_overlap=20,
|
40 |
separators=["\n\n","\n"," ",".",","])
|
41 |
-
|
42 |
-
|
43 |
|
44 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
45 |
|
46 |
def embedding(chunk):
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
def get_conversational_chain():
|
52 |
prompt_template = """
|
@@ -63,12 +63,13 @@ def get_conversational_chain():
|
|
63 |
return chain
|
64 |
|
65 |
def user_call(query):
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
def main():
|
74 |
st.header("Chat with your pdf💁")
|
|
|
33 |
return text
|
34 |
|
35 |
def text_splitter(text):
|
36 |
+
text_splitter = RecursiveCharacterTextSplitter(
|
37 |
# Set a really small chunk size, just to show.
|
38 |
chunk_size=500,
|
39 |
chunk_overlap=20,
|
40 |
separators=["\n\n","\n"," ",".",","])
|
41 |
+
chunks=text_splitter.split_text(text)
|
42 |
+
return chunks
|
43 |
|
44 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
45 |
|
46 |
def embedding(chunk):
|
47 |
+
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
|
48 |
+
vector = Chroma.from_documents(chunk)
|
49 |
+
db = Chroma.from_documents(vector, embeddings, persist_directory="./chroma_db")
|
50 |
|
51 |
def get_conversational_chain():
|
52 |
prompt_template = """
|
|
|
63 |
return chain
|
64 |
|
65 |
def user_call(query):
|
66 |
+
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
|
67 |
+
#client = chromadb.HttpClient(host='127.0.0.1', port=8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))
|
68 |
+
db3 = Chroma(persist_directory="./chroma_db", embedding_function=embeddings)
|
69 |
+
docs = db3.similarity_search(query)
|
70 |
+
chain = get_conversational_chain()
|
71 |
+
response = chain({"input_documents": docs, "question": query}, return_only_outputs=True)
|
72 |
+
st.write("Reply: ", response["output_text"])
|
73 |
|
74 |
def main():
|
75 |
st.header("Chat with your pdf💁")
|