ZeeAI1 commited on
Commit
f695ad6
·
verified ·
1 Parent(s): 0b993cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -46
app.py CHANGED
@@ -71,6 +71,12 @@ def process_single_pdf(file_path):
71
 
72
  # Load PDFs with progress display
73
  def load_pdfs_with_progress(folder_path):
 
 
 
 
 
 
74
  all_text = ""
75
  pdf_files = [os.path.join(folder_path, filename) for filename in os.listdir(folder_path) if filename.endswith('.pdf')]
76
  num_files = len(pdf_files)
@@ -120,49 +126,4 @@ def user_input(user_question):
120
  vector_store = st.session_state.get('vector_store')
121
  if vector_store is None:
122
  return "The app is still loading documents or no documents were successfully loaded."
123
- docs = vector_store.similarity_search(user_question)
124
- context_text = " ".join([doc.page_content for doc in docs])
125
- return generate_summary_with_huggingface(user_question, context_text)
126
-
127
- # Translate text to selected language
128
- def translate_text(text, target_lang):
129
- translation_tokenizer.tgt_lang = target_lang
130
- encoded_text = translation_tokenizer(text, return_tensors="pt")
131
- generated_tokens = translation_model.generate(**encoded_text)
132
- translated_text = translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
133
- return translated_text
134
-
135
- # Main function to run the Streamlit app
136
- def main():
137
- st.markdown(
138
- """
139
- <h1 style="font-size:30px; text-align: center;">
140
- 📄 JusticeCompass: Your AI-Powered Legal Navigator for Swift, Accurate Guidance.
141
- </h1>
142
- """,
143
- unsafe_allow_html=True
144
- )
145
-
146
- if 'loading' not in st.session_state or st.session_state['loading']:
147
- st.session_state['loading'] = True
148
- load_pdfs_with_progress('documents1')
149
-
150
- user_question = st.text_input("Ask a Question:", placeholder="Type your question here...")
151
-
152
- # Display language selection dropdown
153
- selected_language = st.selectbox("Select output language:", list(LANGUAGES.keys()))
154
-
155
- if st.session_state.get('loading', True):
156
- st.info("The app is loading documents in the background. You can type your question now and submit once loading is complete.")
157
-
158
- # Only display "Get Response" button after user enters a question
159
- if user_question:
160
- if st.button("Get Response"):
161
- with st.spinner("Generating response..."):
162
- answer = user_input(user_question)
163
- target_lang_code = LANGUAGES[selected_language]
164
- translated_answer = translate_text(answer, target_lang_code)
165
- st.markdown(f"**🤖 AI ({selected_language}):** {translated_answer}")
166
-
167
- if __name__ == "__main__":
168
- main()
 
71
 
72
  # Load PDFs with progress display
73
  def load_pdfs_with_progress(folder_path):
74
+ if not os.path.exists(folder_path):
75
+ st.error(f"The folder '{folder_path}' does not exist. Please create it and add PDF files.")
76
+ st.session_state['vector_store'] = None
77
+ st.session_state['loading'] = False
78
+ return
79
+
80
  all_text = ""
81
  pdf_files = [os.path.join(folder_path, filename) for filename in os.listdir(folder_path) if filename.endswith('.pdf')]
82
  num_files = len(pdf_files)
 
126
  vector_store = st.session_state.get('vector_store')
127
  if vector_store is None:
128
  return "The app is still loading documents or no documents were successfully loaded."
129
+ docs = vector_store.simi