ZeeAI1 commited on
Commit
b4ab0cc
·
verified ·
1 Parent(s): aec9c17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -81,5 +81,31 @@ def generate_summary_with_huggingface(query, retrieved_text):
81
  return "Error generating summary."
82
 
83
  def user_input(user_question, vector_store):
84
- if vector_store i
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
 
 
 
81
  return "Error generating summary."
82
 
83
  def user_input(user_question, vector_store):
84
+ if vector_store is None:
85
+ return "Vector store is empty."
86
+ try:
87
+ docs = vector_store.similarity_search(user_question)
88
+ context_text = " ".join([doc.page_content for doc in docs])
89
+ return generate_summary_with_huggingface(user_question, context_text)
90
+ except Exception as e:
91
+ st.error(f"Error in similarity search: {e}")
92
+ return "Error in similarity search."
93
+
94
+ def main():
95
+ st.title("📄 Gen AI Lawyers Guide")
96
+ raw_text = fetch_pdf_text_from_folders(PDF_FOLDERS)
97
+ text_chunks = get_text_chunks(raw_text)
98
+ vector_store = load_or_create_vector_store(text_chunks)
99
+
100
+ user_question = st.text_input("Ask a Question:", placeholder="Type your question here...")
101
+
102
+ if st.button("Get Response"):
103
+ if not user_question:
104
+ st.warning("Please enter a question before submitting.")
105
+ else:
106
+ with st.spinner("Generating response..."):
107
+ answer = user_input(user_question, vector_store)
108
+ st.markdown(f"**🤖 AI:** {answer}")
109
 
110
+ if __name__ == "__main__":
111
+ main()