Analysis this 10 years pervious year question paper and tell me if there is pattern of repeating questions , imp topic and I have 3 days to prepare for the exam help me out
cd /tmp/workspace/attachments/0d85c079-ce55-406c-8d96-7aab2eb5fcac/ && python3 -c " import pdfplumber with pdfplumber.open('Peads and Geri.pdf') as pdf: print(f'Total pages: {len(pdf.pages)}') for i, page in enumerate(pdf.pages[:5]): print(f'--- PAGE {i+1} ---') text = page.extract_text() if text: print(text[:2000]) print() "
python3 -c " from pypdf import PdfReader import pdfplumber path = '/tmp/workspace/attachments/0d85c079-ce55-406c-8d96-7aab2eb5fcac/Peads and Geri.pdf' reader = PdfReader(path) print(f'Pages: {len(reader.pages)}') print(f'Encrypted: {reader.is_encrypted}') # Try extracting text with pypdf for i, page in enumerate(reader.pages[:3]): text = page.extract_text() print(f'Page {i+1}: {repr(text[:200]) if text else \"EMPTY\"}') "
python3 -c " import subprocess result = subprocess.run(['pip', 'show', 'pdf2image'], capture_output=True, text=True) print(result.stdout) result2 = subprocess.run(['pip', 'show', 'Pillow'], capture_output=True, text=True) print(result2.stdout) # Check if pymupdf is available result3 = subprocess.run(['pip', 'show', 'pymupdf'], capture_output=True, text=True) print(result3.stdout) result4 = subprocess.run(['pip', 'show', 'fitz'], capture_output=True, text=True) print(result4.stdout) "
python3 -c " import fitz # PyMuPDF doc = fitz.open('/tmp/workspace/attachments/0d85c079-ce55-406c-8d96-7aab2eb5fcac/Peads and Geri.pdf') print(f'Pages: {doc.page_count}') # Save each page as image import os os.makedirs('/tmp/workspace/pdf_pages', exist_ok=True) for i in range(doc.page_count): page = doc[i] mat = fitz.Matrix(2, 2) # 2x zoom for better quality pix = page.get_pixmap(matrix=mat) pix.save(f'/tmp/workspace/pdf_pages/page_{i+1:02d}.png') print(f'Saved page {i+1}') print('Done') " 2>&1
pip install --user pymupdf -q && python3 -c "import fitz; print('fitz ok', fitz.__version__)"
python3 -c " import fitz import os doc = fitz.open('/tmp/workspace/attachments/0d85c079-ce55-406c-8d96-7aab2eb5fcac/Peads and Geri.pdf') print(f'Pages: {doc.page_count}') os.makedirs('/tmp/workspace/pdf_pages', exist_ok=True) for i in range(doc.page_count): page = doc[i] mat = fitz.Matrix(2, 2) pix = page.get_pixmap(matrix=mat) pix.save(f'/tmp/workspace/pdf_pages/page_{i+1:02d}.png') print('All pages saved') os.listdir('/tmp/workspace/pdf_pages') " && ls /tmp/workspace/pdf_pages/
python3 -c " from PIL import Image import os pages_dir = '/tmp/workspace/pdf_pages' output_dir = '/tmp/workspace/pdf_batches' os.makedirs(output_dir, exist_ok=True) # Create 5 batches: pages 1-5, 6-10, 11-15, 16-20, 21-24 batches = [ list(range(1, 6)), list(range(6, 11)), list(range(11, 16)), list(range(16, 21)), list(range(21, 25)) ] for batch_idx, batch in enumerate(batches): images = [] for pg in batch: img = Image.open(f'{pages_dir}/page_{pg:02d}.png') images.append(img) # Stack vertically total_height = sum(img.height for img in images) max_width = max(img.width for img in images) combined = Image.new('RGB', (max_width, total_height), (255, 255, 255)) y_offset = 0 for img in images: combined.paste(img, (0, y_offset)) y_offset += img.height # Resize to keep file manageable (max height 8000px) if combined.height > 8000: ratio = 8000 / combined.height new_w = int(combined.width * ratio) combined = combined.resize((new_w, 8000), Image.LANCZOS) out_path = f'{output_dir}/batch_{batch_idx+1}_pages_{batch[0]}-{batch[-1]}.png' combined.save(out_path, optimize=True, quality=85) size = os.path.getsize(out_path) print(f'Batch {batch_idx+1} (pages {batch[0]}-{batch[-1]}): {combined.size}, {size/1024/1024:.1f} MB -> {out_path}') "
python3 -c " # Try pytesseract for OCR import subprocess result = subprocess.run(['tesseract', '--version'], capture_output=True, text=True) print('Tesseract:', result.stdout[:100], result.stderr[:100]) "
python3 -c " # Try PyMuPDF's OCR - it can use tesseract internally but let's try the text layer # Also check if there's a way to extract using markitdown import subprocess result = subprocess.run(['pip', 'show', 'markitdown'], capture_output=True, text=True) print('markitdown:', result.stdout[:200]) # Try markitdown on the PDF from markitdown import MarkItDown md = MarkItDown() result = md.convert('/tmp/workspace/attachments/0d85c079-ce55-406c-8d96-7aab2eb5fcac/Peads and Geri.pdf') print('Markitdown result length:', len(result.text_content)) print(result.text_content[:3000]) "
# Try using easyocr which might be available python3 -c " import subprocess r = subprocess.run(['pip', 'show', 'easyocr'], capture_output=True, text=True) print(r.stdout[:200]) r2 = subprocess.run(['pip', 'show', 'paddleocr'], capture_output=True, text=True) print(r2.stdout[:200]) # Check what vision/OCR tools are available r3 = subprocess.run(['pip', 'list'], capture_output=True, text=True) # Look for OCR related for line in r3.stdout.split('\n'): if any(x in line.lower() for x in ['ocr', 'vision', 'google', 'azure', 'aws', 'openai', 'anthropic', 'tesseract']): print(line) "
# Try using openai to OCR each page image python3 << 'EOF' import openai import base64 import os client = openai.OpenAI() def ocr_image(image_path): with open(image_path, 'rb') as f: img_data = base64.b64encode(f.read()).decode('utf-8') response = client.chat.completions.create( model="gpt-4o", messages=[{ "role": "user", "content": [ { "type": "image_url", "image_url": {"url": f"data:image/png;base64,{img_data}"} }, { "type": "text", "text": "Extract ALL text from this exam question paper image exactly as written. List every question with its year, question number, and full text. Note any marks allocated." } ] }], max_tokens=4000 ) return response.choices[0].message.content # Test with first batch result = ocr_image('/tmp/workspace/pdf_batches/batch_1_pages_1-5.png') print(result[:3000]) EOF
# Let me check individual page images to understand their content first # and try fetch_image approach via base64 encoding to a temp http server # Actually let me try to use the fetch_image tool path approach differently # First let's look at individual pages directly python3 -c " from PIL import Image import os # Check the size of individual pages for i in range(1, 6): img = Image.open(f'/tmp/workspace/pdf_pages/page_{i:02d}.png') size = os.path.getsize(f'/tmp/workspace/pdf_pages/page_{i:02d}.png') print(f'Page {i}: {img.size}, {size/1024:.0f}KB') "
# Start a simple HTTP server in background to serve the images python3 -c " import http.server import socketserver import threading import os os.chdir('/tmp/workspace') class Handler(http.server.SimpleHTTPRequestHandler): def log_message(self, format, *args): pass httpd = socketserver.TCPServer(('0.0.0.0', 8765), Handler) t = threading.Thread(target=httpd.serve_forever) t.daemon = True t.start() print('Server started on port 8765') # Quick test import urllib.request try: resp = urllib.request.urlopen('http://localhost:8765/pdf_pages/page_01.png', timeout=5) print(f'Test OK: {resp.status} {resp.headers.get(\"Content-Type\")}') except Exception as e: print(f'Test failed: {e}') # Keep alive import time time.sleep(5) " & sleep 3 # Test the server is running curl -s -o /dev/null -w "%{http_code}" http://localhost:8765/pdf_pages/page_01.png
python3 << 'EOF' # Try PyMuPDF's text extraction with OCR flag import fitz doc = fitz.open('/tmp/workspace/attachments/0d85c079-ce55-406c-8d96-7aab2eb5fcac/Peads and Geri.pdf') all_text = [] for i in range(min(5, doc.page_count)): page = doc[i] # Try getting text with various flags text = page.get_text("text", flags=fitz.TEXT_PRESERVE_WHITESPACE) blocks = page.get_text("blocks") words = page.get_text("words") print(f"Page {i+1}: text len={len(text)}, blocks={len(blocks)}, words={len(words)}") if words: print(" Sample words:", [w[4] for w in words[:10]]) all_text.append(text) EOF
pip install --user easyocr -q 2>&1 | tail -5 && python3 -c "import easyocr; print('easyocr OK')" 2>&1 | head -5
analyse_media tool (which uses vision AI) requires a public HTTP URL, not a local file path