Penality commited on
Commit
20218cb
·
verified ·
1 Parent(s): 06fdfd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -0
app.py CHANGED
@@ -9,6 +9,7 @@ together.api_key = "8052996318422f1b9470840fc6ebc94e80676391f07e71cc15951b08bb43
9
 
10
  def clean_text(text):
11
  """Cleans extracted text for better processing by the model."""
 
12
  text = unicodedata.normalize("NFKC", text) # Normalize Unicode characters
13
  text = re.sub(r'\s+', ' ', text).strip() # Remove extra spaces and newlines
14
  text = re.sub(r'[^a-zA-Z0-9.,!?;:\'\"()\-]', ' ', text) # Keep basic punctuation
@@ -17,6 +18,7 @@ def clean_text(text):
17
 
18
  def extract_text_from_pdf(pdf_file):
19
  """Extract and clean text from the uploaded PDF."""
 
20
  try:
21
  with pdfplumber.open(pdf_file) as pdf:
22
  text = " ".join(clean_text(text) for page in pdf.pages if (text := page.extract_text()))
@@ -27,10 +29,12 @@ def extract_text_from_pdf(pdf_file):
27
 
28
  def split_text(text, chunk_size=500):
29
  """Splits text into smaller chunks for better processing."""
 
30
  return [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
31
 
32
  def chatbot(pdf_file, user_question):
33
  """Processes the PDF and answers the user's question."""
 
34
 
35
  # Extract text from the PDF
36
  text = extract_text_from_pdf(pdf_file)
 
9
 
10
  def clean_text(text):
11
  """Cleans extracted text for better processing by the model."""
12
+ print("cleaning")
13
  text = unicodedata.normalize("NFKC", text) # Normalize Unicode characters
14
  text = re.sub(r'\s+', ' ', text).strip() # Remove extra spaces and newlines
15
  text = re.sub(r'[^a-zA-Z0-9.,!?;:\'\"()\-]', ' ', text) # Keep basic punctuation
 
18
 
19
  def extract_text_from_pdf(pdf_file):
20
  """Extract and clean text from the uploaded PDF."""
21
+ print("extracting")
22
  try:
23
  with pdfplumber.open(pdf_file) as pdf:
24
  text = " ".join(clean_text(text) for page in pdf.pages if (text := page.extract_text()))
 
29
 
30
  def split_text(text, chunk_size=500):
31
  """Splits text into smaller chunks for better processing."""
32
+ print("splitting")
33
  return [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
34
 
35
  def chatbot(pdf_file, user_question):
36
  """Processes the PDF and answers the user's question."""
37
+ print("chatbot start")
38
 
39
  # Extract text from the PDF
40
  text = extract_text_from_pdf(pdf_file)