MCPcopy Create free account
hub / github.com/PromtEngineer/localGPT / process_pdf

Method process_pdf

backend/simple_pdf_processor.py:66–112  ·  view source on GitHub ↗

Process a PDF file and store in database

(self, pdf_bytes: bytes, filename: str, session_id: str)

Source from the content-addressed store, hash-verified

64 return ""
65
66 def process_pdf(self, pdf_bytes: bytes, filename: str, session_id: str) -> Dict[str, Any]:
67 """Process a PDF file and store in database"""
68 print(f"📄 Processing PDF: {filename}")
69
70 # Extract text
71 text = self.extract_text_from_pdf(pdf_bytes)
72 if not text:
73 return {
74 "success": False,
75 "error": "Could not extract text from PDF",
76 "filename": filename
77 }
78
79 print(f"📝 Extracted {len(text)} characters from {filename}")
80
81 # Store in database
82 document_id = str(uuid.uuid4())
83 now = datetime.now().isoformat()
84
85 try:
86 conn = sqlite3.connect(self.db_path)
87
88 # Store document
89 conn.execute('''
90 INSERT INTO pdf_documents (id, session_id, filename, content, created_at)
91 VALUES (?, ?, ?, ?, ?)
92 ''', (document_id, session_id, filename, text, now))
93
94 conn.commit()
95 conn.close()
96
97 print(f"💾 Stored document {filename} in database")
98
99 return {
100 "success": True,
101 "filename": filename,
102 "file_id": document_id,
103 "text_length": len(text)
104 }
105
106 except Exception as e:
107 print(f"❌ Error storing in database: {str(e)}")
108 return {
109 "success": False,
110 "error": f"Database storage failed: {str(e)}",
111 "filename": filename
112 }
113
114 def get_session_documents(self, session_id: str) -> List[Dict[str, Any]]:
115 """Get all documents for a session"""

Callers

nothing calls this directly

Calls 1

extract_text_from_pdfMethod · 0.95

Tested by

no test coverage detected