Spaces:
Sleeping
Sleeping
Update backend/main.py
Browse files- 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
|
| 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 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
if not text.strip():
|
| 96 |
-
|
| 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(
|
| 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)
|