trish06 commited on
Commit
7ee987a
·
verified ·
1 Parent(s): d00977f

Update backend/main.py

Browse files
Files changed (1) hide show
  1. backend/main.py +8 -8
backend/main.py CHANGED
@@ -5,7 +5,7 @@ import tempfile
5
  from pathlib import Path
6
  from typing import List
7
 
8
- import pdfplumber
9
  from groq import Groq
10
  from fastapi import FastAPI, File, UploadFile, HTTPException
11
  from fastapi.middleware.cors import CORSMiddleware
@@ -86,14 +86,14 @@ Return ONLY valid JSON (no markdown fences, no extra text) using this schema:
86
 
87
  def extract_text_from_pdf(pdf_path: str) -> str:
88
  text = ""
89
- with pdfplumber.open(pdf_path) as pdf:
90
- for page in pdf.pages:
91
- page_text = page.extract_text()
92
- if page_text:
93
- text += page_text + "\n"
94
 
95
  if not text.strip():
96
- raise ValueError("PDF text extraction failed.")
97
 
98
  if len(text.strip()) < 500:
99
  text = text[:2000]
@@ -109,7 +109,7 @@ def extract_text_from_pdf(pdf_path: str) -> str:
109
  text, re.IGNORECASE | re.DOTALL | re.MULTILINE
110
  )
111
 
112
- if methods_match and len(methods_match.group(1).strip()) > 200:
113
  text = methods_match.group(2)
114
  else:
115
  chars = len(text)
 
5
  from pathlib import Path
6
  from typing import List
7
 
8
+ import fitz
9
  from groq import Groq
10
  from fastapi import FastAPI, File, UploadFile, HTTPException
11
  from fastapi.middleware.cors import CORSMiddleware
 
86
 
87
  def extract_text_from_pdf(pdf_path: str) -> str:
88
  text = ""
89
+
90
+ doc = fitz.open(pdf_path)
91
+
92
+ for page in doc:
93
+ text += page.get_text()
94
 
95
  if not text.strip():
96
+ raise ValueError("PDF text extraction failed.")
97
 
98
  if len(text.strip()) < 500:
99
  text = text[:2000]
 
109
  text, re.IGNORECASE | re.DOTALL | re.MULTILINE
110
  )
111
 
112
+ if methods_match and len(methods_match.group(2).strip()) > 200:
113
  text = methods_match.group(2)
114
  else:
115
  chars = len(text)