Views
No views yet
text-multilingual-embedding-002 model. The generated embeddings are stored in a JSON file, ready for use in Retrieval Augmented Generation (RAG) systems or other downstream applications.text-multilingual-embedding-002 model for embeddings, supporting a wide range of languages.PyMuPDF to extract text blocks and images, and Camelot to accurately extract tabular data.gemma Python library) with specific prompts to generate rich, descriptive text in French. This step runs locally and does not incur direct API costs.text-multilingual-embedding-002 model (via Vertex AI).google.colab.auth.authenticate_user().gcloud auth application-default login).1git clone https://huggingface.co/Anonymous1223334444/pdf-multimodal-multilingual-embedding-pipeline
2cd pdf-multimodal-multilingual-embedding-pipelinepip install -r requirements.txtPyMuPDF and Camelot to function correctly.1# Update package list
2sudo apt-get update
3# Install Ghostscript (required by Camelot)
4sudo apt-get install -y ghostscript
5# Install python3-tk (required by some PyMuPDF functionalities)
6sudo apt-get install -y python3-tk
7# Install OpenCV (via apt, for camelot-py[cv])
8sudo apt-get install -y libopencv-dev python3-opencvcamelot-py might differ. Refer to the Camelot documentation for more details.1export GOOGLE_CLOUD_PROJECT="your-gcp-project-id"
2export VERTEX_AI_LOCATION="us-central1" # Or your preferred Vertex AI region (e.g., us-east4)your-gcp-project-id and us-central1 with your actual Google Cloud Project ID and Vertex AI region.docs directory in the root of the repository and place your PDF documents inside it.pdf-multimodal-multilingual-embedding-pipeline/
├── docs/
│ └── your_document.pdf
└── another_document.pdfpython run_pipeline.pyembeddings_statistiques_multimodal.json) and extracted assets will be saved in the output/ directory.Runtime > Change runtime type and select T4 GPU or V100 GPU.1!pip uninstall -y camelot camelot-py # Ensure clean install
2!pip install PyMuPDF
3!apt-get update
4!apt-get install -y ghostscript python3-tk libopencv-dev python3-opencv
5!pip install camelot-py[cv] google-cloud-aiplatform tiktoken pandas beautifulsoup4 Pillow gemma jax jaxlib numpy1from google.colab import auth
2auth.authenticate_user()1import os
2# Replace with your actual Google Cloud Project ID
3os.environ["GOOGLE_CLOUD_PROJECT"] = "YOUR_GCP_PROJECT_ID_HERE"
4# Set your preferred Vertex AI location (e.g., "us-central1", "us-east4")
5os.environ["VERTEX_AI_LOCATION"] = "us-central1"
6
7# Critical: Adjust JAX memory allocation for Gemma
8os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"]="1.00"docs within /content/.
1# Example for uploading
2from google.colab import files
3import os
4from pathlib import Path
5
6PDF_DIRECTORY = Path("/content/docs")
7PDF_DIRECTORY.mkdir(parents=True, exist_ok=True)
8uploaded = files.upload()
9for filename in uploaded.keys():
10 os.rename(filename, PDF_DIRECTORY / filename)src/pdf_processor.py, src/embedding_utils.py and run_pipeline.py into Colab cells and execute. Make sure to execute embedding_utils.py content first, then pdf_processor.py content, then run_pipeline.py content, or combine them logically into your notebook.embeddings_statistiques_multimodal.json: A JSON file containing all generated embeddings and their metadata.output/extracted_graphs/: Directory containing extracted images (PNG format).output/extracted_tables/: Directory containing HTML representations of extracted tables.embeddings_statistiques_multimodal.json Entry1[
2 {
3 "pdf_file": "sample.pdf",
4 "page_number": 1,
5 "chunk_id": "text_0",
6 "content_type": "text",
7 "text_content": "This is a chunk of text extracted from the first page of the document...",
8 "embedding": [0.123, -0.456, ..., 0.789],
9 "pdf_title": "Sample Document",
10 "pdf_subject": "Data Analysis",
11 "pdf_keywords": "statistics, report"
12 },
13 {
14 "pdf_file": "sample.pdf",
15 "page_number": 2,
16 "chunk_id": "table_0",
17 "content_type": "table",
18 "text_content": "Description en français du tableau: Ce tableau présente les ventes mensuelles par région. Il inclut les colonnes Mois, Région, et Ventes. La région Nord a la plus forte croissance...",
19 "embedding": [-0.987, 0.654, ..., 0.321],
20 "table_html_url": "/static/extracted_tables/sample_p2_table0.html",
21 "image_url": "/static/extracted_graphs/sample_p2_table0.png",
22 "pdf_title": "Sample Document",
23 "pdf_subject": "Data Analysis",
24 "pdf_keywords": "statistics, report"
25 },
26 {
27 "pdf_file": "sample.pdf",
28 "page_number": 3,
29 "chunk_id": "image_0",
30 "content_type": "image",
31 "text_content": "Description en français de l'image: Ce graphique est un histogramme montrant la répartition des âges dans la population. L'axe des X représente les tranches d'âge et l'axe des Y la fréquence. La majorité de la population se situe entre 25 et 40 ans.",
32 "embedding": [0.456, -0.789, ..., 0.123],
33 "image_url": "/static/extracted_graphs/sample_p3_img0.png",
34 "pdf_title": "Sample Document",
35 "pdf_subject": "Data Analysis",
36 "pdf_keywords": "statistics, report"
37 }
38]