anmolsahai commited on
Commit
bb5122d
1 Parent(s): f4f2ae6
Files changed (1) hide show
  1. langchain_pipeline.py +9 -4
langchain_pipeline.py CHANGED
@@ -4,7 +4,6 @@ from pdf2docx import Converter
4
  from io import BytesIO
5
  import fitz # PyMuPDF
6
  import re
7
- from tempfile import NamedTemporaryFile
8
  from langchain_core.prompts import PromptTemplate
9
  from langchain_openai import OpenAIEmbeddings
10
  from langchain_anthropic import ChatAnthropic
@@ -119,8 +118,14 @@ def create_redlined_word_doc(formatted_text, changes, output_path):
119
  doc.save(output_path)
120
  print(f"Redlined document saved to {output_path}")
121
 
122
- def pipeline(file, model_name, balance_type, apsn_transactions, max_fees_per_day, min_overdrawn_fee, min_transaction_overdraft):
123
- disclosure_text = high_level.extract_text(file)
 
 
 
 
 
 
124
 
125
  prompt_template = """
126
  law context:
@@ -180,7 +185,7 @@ reasons for changes citing caselaw
180
  if not os.path.exists(output_directory):
181
  os.makedirs(output_directory)
182
 
183
- formatted_text = extract_text_with_formatting(file)
184
 
185
  create_redlined_word_doc(formatted_text, changes, output_path)
186
 
 
4
  from io import BytesIO
5
  import fitz # PyMuPDF
6
  import re
 
7
  from langchain_core.prompts import PromptTemplate
8
  from langchain_openai import OpenAIEmbeddings
9
  from langchain_anthropic import ChatAnthropic
 
118
  doc.save(output_path)
119
  print(f"Redlined document saved to {output_path}")
120
 
121
+ def pipeline(uploaded_file, model_name, balance_type, apsn_transactions, max_fees_per_day, min_overdrawn_fee, min_transaction_overdraft):
122
+ # Save the uploaded file to a temporary file
123
+ with NamedTemporaryFile(delete=False, suffix='.pdf') as tmp:
124
+ tmp.write(uploaded_file.read())
125
+ tmp_path = tmp.name
126
+
127
+ # Extract text from the uploaded file
128
+ disclosure_text = high_level.extract_text(tmp_path)
129
 
130
  prompt_template = """
131
  law context:
 
185
  if not os.path.exists(output_directory):
186
  os.makedirs(output_directory)
187
 
188
+ formatted_text = extract_text_with_formatting(tmp_path)
189
 
190
  create_redlined_word_doc(formatted_text, changes, output_path)
191