Paul-Joshi commited on
Commit
5ac0ce9
·
verified ·
1 Parent(s): 8370d00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -31,12 +31,9 @@ def method_get_text_chunks(text):
31
  return doc_splits
32
 
33
  #convert text chunks into embeddings and store in vector database
34
- def method_get_vectorstore(document_chunks,nomic_apikey=None):
35
- # create the open-source embedding function
36
- if nomic_apikey is None:
37
- embeddings = HuggingFaceEmbeddings()
38
- else:
39
- embeddings = NomicEmbeddings(model="nomic-embed-text-v1.5")
40
 
41
  # create a vectorstore from the chunks
42
  vector_store = Chroma.from_documents(document_chunks, embeddings)
@@ -77,33 +74,40 @@ def main():
77
  with st.sidebar:
78
  st.header("Settings")
79
  website_url = st.text_input("Website URL")
80
- nomic_apikey = st.text_input("NOMIC API Key for Embeddings")
81
 
82
  if website_url is None or website_url == "":
83
  st.info("Please enter a website URL")
84
 
85
  else:
86
  # Input fields
87
- question = st.text_input("Question")
88
-
89
- # Button to process input
90
- if st.button('Query Documents'):
91
- with st.spinner('Processing...'):
92
- st.write(nomic_apikey)
93
- if nomic_apikey is None or nomic_apikey == "":
94
- nomic_apikey = None
95
- else:
96
- # Set the environment variable
97
- os.environ['NOMIC_API_KEY'] = nomic_apikey
98
  # get pdf text
99
  raw_text = method_get_website_text(website_url)
100
  # get the text chunks
101
  doc_splits = method_get_text_chunks(raw_text)
102
- #access the environment variable
103
- nomic_apikey = os.environ['NOMIC_API_KEY']
104
  # create vector store
105
- vector_store = method_get_vectorstore(doc_splits,nomic_apikey)
106
  # Generate response using the RAG pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  answer = get_context_retriever_chain(vector_store,question)
108
  # Display the generated answer
109
  split_string = "Question: " + str(question)
 
31
  return doc_splits
32
 
33
  #convert text chunks into embeddings and store in vector database
34
+ def method_get_vectorstore(document_chunks):
35
+ embeddings = HuggingFaceEmbeddings()
36
+ #embeddings = NomicEmbeddings(model="nomic-embed-text-v1.5")
 
 
 
37
 
38
  # create a vectorstore from the chunks
39
  vector_store = Chroma.from_documents(document_chunks, embeddings)
 
74
  with st.sidebar:
75
  st.header("Settings")
76
  website_url = st.text_input("Website URL")
 
77
 
78
  if website_url is None or website_url == "":
79
  st.info("Please enter a website URL")
80
 
81
  else:
82
  # Input fields
83
+ st.subheader('Your are gonna interact with the below Website:')
84
+ st.button("Start", type="primary")
85
+ st.subheader('Click on the Start button', divider='rainbow')
86
+
87
+ # Button to pre-process input
88
+ if st.button("Reset"):
89
+ with st.spinner('Tokenizing and Embedding the Website Data'):
 
 
 
 
90
  # get pdf text
91
  raw_text = method_get_website_text(website_url)
92
  # get the text chunks
93
  doc_splits = method_get_text_chunks(raw_text)
 
 
94
  # create vector store
95
+ vector_store = method_get_vectorstore(doc_splits)
96
  # Generate response using the RAG pipeline
97
+
98
+ # Input fields
99
+ question = st.text_input("Question")
100
+
101
+ # Button to process input and get output
102
+ if st.button('Query Documents'):
103
+ with st.spinner('Processing...'):
104
+ # # get pdf text
105
+ # raw_text = method_get_website_text(website_url)
106
+ # # get the text chunks
107
+ # doc_splits = method_get_text_chunks(raw_text)
108
+ # # create vector store
109
+ # vector_store = method_get_vectorstore(doc_splits)
110
+ # # Generate response using the RAG pipeline
111
  answer = get_context_retriever_chain(vector_store,question)
112
  # Display the generated answer
113
  split_string = "Question: " + str(question)