1 line
12 KiB
JSON
1 line
12 KiB
JSON
{"repo": "arehh04/agentic-doc-parse-system", "files": {"run_on_colab.ipynb": {"4c439c08301a1595768670169f46fe172b7859e6": {"t": 1785745509.3967447, "n": 5525, "h": "7c234ba0c8ad259d", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# 🚀 SROIE GPU Pipeline on Google Colab\\n\",\n \"This notebook is configured to run your SROIE Agentic Pipeline using a free NVIDIA T4 GPU on Google Colab.\\n\",\n \"\\n\",\n \"### **Step 1: Enable the GPU**\\n\",\n \"1. Go to **Runtime** > **Change runtime type** in the top menu.\\n\",\n \"2. Select **T4 GPU** under Hardware accelerator and click Save.\\n\",\n \"3. Run the cell below to verify the GPU is active.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!nvidia-smi\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 2: Upload Your Project Files**\\n\",\n \"Since your project is local, the easiest way to bring it here is to zip it up:\\n\",\n \"1. Zip your entire `sroie-pipeline` folder on your computer (call it `sroie-pipeline.zip`).\\n\",\n \"2. Click the **Folder icon** on the left sidebar of Colab.\\n\",\n \"3. Click the **Upload** icon and select your `sroie-pipeline.zip` file.\\n\",\n \"4. Run the cell below to unzip it.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!unzip -q sroie-pipeline.zip -d /content/\\n\",\n \"%cd /content/sroie-pipeline\\n\",\n \"!ls\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 3: Install Dependencies & GPU Libraries**\\n\",\n \"This installs your requirements and ensures PyTorch uses the GPU (CUDA).\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!pip install -r requirements.txt\\n\",\n \"# Install the CUDA version of PyTorch for Docling\\n\",\n \"!pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 4: Configure GPU for Docling**\\n\",\n \"We need to update your `parsing_agent.py` to tell it to use the GPU. This script does it automatically for you.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"parsing_agent_code = \\\"\\\"\\\"import os\\n\",\n \"from parser.document_parser import parse_sroie_box_file\\n\",\n \"from docling.document_converter import DocumentConverter\\n\",\n \"from docling.datamodel.pipeline_options import PipelineOptions, RapidOcrOptions\\n\",\n \"from docling.datamodel.base_models import AcceleratorOptions, AcceleratorDevice\\n\",\n \"\\n\",\n \"class DocumentParsingAgent:\\n\",\n \" def __init__(self):\\n\",\n \" pipeline_options = PipelineOptions()\\n\",\n \" pipeline_options.ocr_options = RapidOcrOptions(backend=\\\"torch\\\")\\n\",\n \" pipeline_options.accelerator_options = AcceleratorOptions(device=AcceleratorDevice.CUDA)\\n\",\n \" self.converter = DocumentConverter(pipeline_options=pipeline_options)\\n\",\n \" \\n\",\n \" def parse_file(self, file_path: str) -> str:\\n\",\n \" if not os.path.exists(file_path):\\n\",\n \" raise FileNotFoundError(f\\\"File not found: {file_path}\\\")\\n\",\n \" ext = file_path.lower().split('.')[-1]\\n\",\n \" if ext == 'txt':\\n\",\n \" return parse_sroie_box_file(file_path)\\n\",\n \" elif ext in ['jpg', 'jpeg', 'png', 'pdf']:\\n\",\n \" print(f\\\"[Docling - GPU] Converting image: {file_path}\\\")\\n\",\n \" result = self.converter.convert(file_path)\\n\",\n \" return result.document.export_to_markdown()\\n\",\n \" else:\\n\",\n \" raise NotImplementedError(f\\\"Parsing for extension .{ext} not yet implemented.\\\")\\n\",\n \"\\\"\\\"\\\"\\n\",\n \"\\n\",\n \"with open(\\\"agents/parsing_agent.py\\\", \\\"w\\\") as f:\\n\",\n \" f.write(parsing_agent_code)\\n\",\n \"print(\\\"parsing_agent.py updated for GPU!\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 5: Set up Environment Variables**\\n\",\n \"Run this cell and securely paste your API keys when prompted. It will generate your `.env` file.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"import getpass\\n\",\n \"\\n\",\n \"print(\\\"Enter your DEEPSEEK_API_KEY:\\\")\\n\",\n \"deepseek_key = getpass.getpass()\\n\",\n \"\\n\",\n \"print(\\\"Enter your SUPABASE_URL:\\\")\\n\",\n \"supabase_url = getpass.getpass()\\n\",\n \"\\n\",\n \"print(\\\"Enter your SUPABASE_KEY:\\\")\\n\",\n \"supabase_key = getpass.getpass()\\n\",\n \"\\n\",\n \"with open(\\\".env\\\", \\\"w\\\") as f:\\n\",\n \" f.write(f\\\"DEEPSEEK_API_KEY={deepseek_key}\\\\n\\\")\\n\",\n \" f.write(f\\\"SUPABASE_URL={supabase_url}\\\\n\\\")\\n\",\n \" f.write(f\\\"SUPABASE_KEY={supabase_key}\\\\n\\\")\\n\",\n \"print(\\\".env file successfully created!\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 6: Run the Full Dataset at Lightning Speed! ⚡**\\n\",\n \"With the GPU enabled, the bottleneck is removed. Let's run `main.py`.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!python main.py\"\n ]\n }\n ],\n \"metadata\": {\n \"accelerator\": \"GPU\",\n \"colab\": {\n \"gpuType\": \"T4\",\n \"provenance\": []\n },\n \"kernelspec\": {\n \"display_name\": \"Python 3\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"name\": \"python\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 0\n}\n"}, "1ab3840fc84ad028ccebfd6c7c57d3a97f49523c": {"t": 1785753747.5738554, "n": 5525, "h": "7c234ba0c8ad259d", "c": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# 🚀 SROIE GPU Pipeline on Google Colab\\n\",\n \"This notebook is configured to run your SROIE Agentic Pipeline using a free NVIDIA T4 GPU on Google Colab.\\n\",\n \"\\n\",\n \"### **Step 1: Enable the GPU**\\n\",\n \"1. Go to **Runtime** > **Change runtime type** in the top menu.\\n\",\n \"2. Select **T4 GPU** under Hardware accelerator and click Save.\\n\",\n \"3. Run the cell below to verify the GPU is active.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!nvidia-smi\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 2: Upload Your Project Files**\\n\",\n \"Since your project is local, the easiest way to bring it here is to zip it up:\\n\",\n \"1. Zip your entire `sroie-pipeline` folder on your computer (call it `sroie-pipeline.zip`).\\n\",\n \"2. Click the **Folder icon** on the left sidebar of Colab.\\n\",\n \"3. Click the **Upload** icon and select your `sroie-pipeline.zip` file.\\n\",\n \"4. Run the cell below to unzip it.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!unzip -q sroie-pipeline.zip -d /content/\\n\",\n \"%cd /content/sroie-pipeline\\n\",\n \"!ls\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 3: Install Dependencies & GPU Libraries**\\n\",\n \"This installs your requirements and ensures PyTorch uses the GPU (CUDA).\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!pip install -r requirements.txt\\n\",\n \"# Install the CUDA version of PyTorch for Docling\\n\",\n \"!pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 4: Configure GPU for Docling**\\n\",\n \"We need to update your `parsing_agent.py` to tell it to use the GPU. This script does it automatically for you.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"parsing_agent_code = \\\"\\\"\\\"import os\\n\",\n \"from parser.document_parser import parse_sroie_box_file\\n\",\n \"from docling.document_converter import DocumentConverter\\n\",\n \"from docling.datamodel.pipeline_options import PipelineOptions, RapidOcrOptions\\n\",\n \"from docling.datamodel.base_models import AcceleratorOptions, AcceleratorDevice\\n\",\n \"\\n\",\n \"class DocumentParsingAgent:\\n\",\n \" def __init__(self):\\n\",\n \" pipeline_options = PipelineOptions()\\n\",\n \" pipeline_options.ocr_options = RapidOcrOptions(backend=\\\"torch\\\")\\n\",\n \" pipeline_options.accelerator_options = AcceleratorOptions(device=AcceleratorDevice.CUDA)\\n\",\n \" self.converter = DocumentConverter(pipeline_options=pipeline_options)\\n\",\n \" \\n\",\n \" def parse_file(self, file_path: str) -> str:\\n\",\n \" if not os.path.exists(file_path):\\n\",\n \" raise FileNotFoundError(f\\\"File not found: {file_path}\\\")\\n\",\n \" ext = file_path.lower().split('.')[-1]\\n\",\n \" if ext == 'txt':\\n\",\n \" return parse_sroie_box_file(file_path)\\n\",\n \" elif ext in ['jpg', 'jpeg', 'png', 'pdf']:\\n\",\n \" print(f\\\"[Docling - GPU] Converting image: {file_path}\\\")\\n\",\n \" result = self.converter.convert(file_path)\\n\",\n \" return result.document.export_to_markdown()\\n\",\n \" else:\\n\",\n \" raise NotImplementedError(f\\\"Parsing for extension .{ext} not yet implemented.\\\")\\n\",\n \"\\\"\\\"\\\"\\n\",\n \"\\n\",\n \"with open(\\\"agents/parsing_agent.py\\\", \\\"w\\\") as f:\\n\",\n \" f.write(parsing_agent_code)\\n\",\n \"print(\\\"parsing_agent.py updated for GPU!\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 5: Set up Environment Variables**\\n\",\n \"Run this cell and securely paste your API keys when prompted. It will generate your `.env` file.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"import getpass\\n\",\n \"\\n\",\n \"print(\\\"Enter your DEEPSEEK_API_KEY:\\\")\\n\",\n \"deepseek_key = getpass.getpass()\\n\",\n \"\\n\",\n \"print(\\\"Enter your SUPABASE_URL:\\\")\\n\",\n \"supabase_url = getpass.getpass()\\n\",\n \"\\n\",\n \"print(\\\"Enter your SUPABASE_KEY:\\\")\\n\",\n \"supabase_key = getpass.getpass()\\n\",\n \"\\n\",\n \"with open(\\\".env\\\", \\\"w\\\") as f:\\n\",\n \" f.write(f\\\"DEEPSEEK_API_KEY={deepseek_key}\\\\n\\\")\\n\",\n \" f.write(f\\\"SUPABASE_URL={supabase_url}\\\\n\\\")\\n\",\n \" f.write(f\\\"SUPABASE_KEY={supabase_key}\\\\n\\\")\\n\",\n \"print(\\\".env file successfully created!\\\")\"\n ]\n },\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"### **Step 6: Run the Full Dataset at Lightning Speed! ⚡**\\n\",\n \"With the GPU enabled, the bottleneck is removed. Let's run `main.py`.\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"!python main.py\"\n ]\n }\n ],\n \"metadata\": {\n \"accelerator\": \"GPU\",\n \"colab\": {\n \"gpuType\": \"T4\",\n \"provenance\": []\n },\n \"kernelspec\": {\n \"display_name\": \"Python 3\",\n \"name\": \"python3\"\n },\n \"language_info\": {\n \"name\": \"python\"\n }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 0\n}\n"}}}} |