Spaces:
Sleeping
Sleeping
import fitz # PyMuPDF | |
MAX_PAGES = 5 # fazla token yememesi için sınır | |
def extract_text_from_pdf(pdf_input): | |
try: | |
# Hugging Face ortamında pdf_input bir file-like objedir (upload edilen dosya) | |
if hasattr(pdf_input, "read"): | |
doc = fitz.open(stream=pdf_input.read(), filetype="pdf") | |
elif isinstance(pdf_input, str): | |
doc = fitz.open(pdf_input) | |
else: | |
return "[ERROR] Geçersiz PDF girişi" | |
total_pages = len(doc) | |
text = "" | |
for i in range(min(MAX_PAGES, total_pages)): | |
text += doc[i].get_text() | |
doc.close() | |
if total_pages > MAX_PAGES: | |
text += f"\n\n[INFO] PDF {total_pages} sayfa. Yalnızca ilk {MAX_PAGES} sayfa işlendi." | |
return text | |
except Exception as e: | |
return f"[ERROR] PDF İşleme Hatası: {str(e)}" | |