samim2024 commited on
Commit
b0bd22c
·
verified ·
1 Parent(s): ec2a1c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -65,10 +65,8 @@ def create_langchain_index(input_text):
65
  # load it into Chroma
66
  db = Chroma.from_documents(docs, embeddings)
67
  persist_directory = "chroma_db"
68
- vectordb = Chroma.from_documents(
69
- documents=docs, embedding=embeddings, persist_directory=persist_directory
70
- )
71
- new_db = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
72
  return db
73
 
74
  # @st.cache_resource
@@ -82,7 +80,7 @@ def create_langchain_index(input_text):
82
 
83
 
84
  @st.cache_data
85
- def get_response(input_text,query):
86
  print(f"--querying---{query}")
87
  retrieval_chain = RetrievalQA.from_chain_type(llm, chain_type="stuff", retriever=db.as_retriever())
88
  response = retrieval_chain.run(query)
@@ -102,15 +100,15 @@ tweet_response = ""
102
  ln_response = ""
103
  # if st.button("Load"):
104
  if input_text:
105
- index = create_langchain_index(input_text)
106
  summary_query ="Write a 100 words summary of the document"
107
- summary_response = get_response(input_text,summary_query)
108
 
109
  tweet_query ="Write a twitter tweet"
110
- tweet_response = get_response(input_text,tweet_query)
111
 
112
  ln_query ="Write a linkedin post for the document"
113
- ln_response = get_response(input_text,ln_query)
114
 
115
 
116
  with st.expander('Page Summary'):
@@ -127,8 +125,8 @@ st.session_state.input_text = ''
127
  question=st.text_input("Ask a question from the link you shared...")
128
  if st.button("Ask"):
129
  if question:
130
- index = create_langchain_index(input_text)
131
- response = get_response(input_text,question)
132
  st.write(response)
133
  else:
134
  st.warning("Please enter a question.")
 
65
  # load it into Chroma
66
  db = Chroma.from_documents(docs, embeddings)
67
  persist_directory = "chroma_db"
68
+ #vectordb = Chroma.from_documents(documents=docs, embedding=embeddings, persist_directory=persist_directory)
69
+ #new_db = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
 
 
70
  return db
71
 
72
  # @st.cache_resource
 
80
 
81
 
82
  @st.cache_data
83
+ def get_response(input_text,query,db):
84
  print(f"--querying---{query}")
85
  retrieval_chain = RetrievalQA.from_chain_type(llm, chain_type="stuff", retriever=db.as_retriever())
86
  response = retrieval_chain.run(query)
 
100
  ln_response = ""
101
  # if st.button("Load"):
102
  if input_text:
103
+ db = create_langchain_index(input_text)
104
  summary_query ="Write a 100 words summary of the document"
105
+ summary_response = get_response(input_text,summary_query,db)
106
 
107
  tweet_query ="Write a twitter tweet"
108
+ tweet_response = get_response(input_text,tweet_query,db)
109
 
110
  ln_query ="Write a linkedin post for the document"
111
+ ln_response = get_response(input_text,ln_query,db)
112
 
113
 
114
  with st.expander('Page Summary'):
 
125
  question=st.text_input("Ask a question from the link you shared...")
126
  if st.button("Ask"):
127
  if question:
128
+ db = create_langchain_index(input_text)
129
+ response = get_response(input_text,question,db)
130
  st.write(response)
131
  else:
132
  st.warning("Please enter a question.")