{"id":49592750,"url":"https://github.com/ceodaniyal/universal-llm-ocr","last_synced_at":"2026-05-04T01:40:11.771Z","repository":{"id":268116827,"uuid":"903367461","full_name":"ceodaniyal/universal-llm-ocr","owner":"ceodaniyal","description":"This repository contains a Python script to extract text from images using OpenAI's GPT-4 API. The script supports text extraction from both online image URLs and locally stored images (converted to base64). It ensures accurate and structured text extraction, making it a powerful tool for OCR-like tasks. The extracted text is saved to a file","archived":false,"fork":false,"pushed_at":"2025-12-11T09:17:03.000Z","size":6,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-04T01:39:49.871Z","etag":null,"topics":["api-integration","base64","gpt-4","gpt-4o","gpt-4o-mini","image-ocr","image-processing","image-to-text","ocr","openai","python","text-analysis","text-extraction"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ceodaniyal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-14T12:28:47.000Z","updated_at":"2025-12-11T09:17:07.000Z","dependencies_parsed_at":"2025-12-12T11:01:08.365Z","dependency_job_id":null,"html_url":"https://github.com/ceodaniyal/universal-llm-ocr","commit_stats":null,"previous_names":["ceodaniyal/image_to_text_gpt-4o-mini","ceodaniyal/universal-llm-ocr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ceodaniyal/universal-llm-ocr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceodaniyal%2Funiversal-llm-ocr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceodaniyal%2Funiversal-llm-ocr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceodaniyal%2Funiversal-llm-ocr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceodaniyal%2Funiversal-llm-ocr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceodaniyal","download_url":"https://codeload.github.com/ceodaniyal/universal-llm-ocr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceodaniyal%2Funiversal-llm-ocr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32591603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-integration","base64","gpt-4","gpt-4o","gpt-4o-mini","image-ocr","image-processing","image-to-text","ocr","openai","python","text-analysis","text-extraction"],"created_at":"2026-05-04T01:40:11.035Z","updated_at":"2026-05-04T01:40:11.727Z","avatar_url":"https://github.com/ceodaniyal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Universal LLM-based OCR (Image → Text Extraction)**\n\nThis project demonstrates how to perform **OCR (Optical Character Recognition)** using **any Large Language Model (LLM)** that supports image input via the **OpenAI-compatible SDK** (OpenAI, OpenRouter, Groq, Together, etc.).\n\nIt works with models such as:\n\n* GPT-4o / GPT-4o-mini\n* Llama Vision models\n* Claude Vision (via OpenAI-compatible routers)\n* Any future LLM that accepts `\"image_url\"` or `\"image_base64\"`\n\n---\n\n## 🚀 **Features**\n\n* **LLM-powered OCR (not traditional Tesseract OCR)**\n* Works with **any model endpoint** that accepts images\n* **Supports:**\n\n  * 🌐 Image URLs\n  * 🖼️ Local images (converted to Base64)\n* **Preserves structure \u0026 formatting**\n* Output can be printed or saved to a text file\n* Easily extendable to:\n\n  * JSON output\n  * Multi-image extraction\n  * PDF → Image → Text pipelines\n\n---\n\n## 📦 **Requirements**\n\n* Python 3.8+\n* `openai` (or compatible OpenRouter SDK)\n* `base64` (comes with Python)\n\nInstall dependencies:\n\n```bash\npip install openai python-dotenv\n```\n\n---\n\n## ⚙️ **Configuration**\n\nSet up your API key:\n\n```python\nclient = OpenAI(\n    base_url=\"https://openrouter.ai/api/v1\",\n    api_key=os.getenv(\"OPENROUTER_API_KEY\")\n)\n```\n\nYou can replace the base URL or model with **any LLM endpoint**.\n\n---\n\n## 🧠 **Why LLM-based OCR?**\n\nUnlike classical OCR tools (Tesseract, EasyOCR), LLMs:\n\n* Understand complex layouts\n* Extract text from low-quality images\n* Preserve meaning, structure, labels\n* Interpret tables, paragraphs, and mixed fonts\n\nThis project shows how to use LLMs as intelligent OCR engines.\n\n---\n\n## 🧰 **Usage**\n\n### ✔️ **Extract Text from an Image URL**\n\n```python\nimage_url = \"https://example.com/image.jpg\"\nextracted_text = image_to_text_from_url(image_url)\n\nwith open(\"output.txt\", \"a\", encoding=\"utf-8\") as f:\n    f.write(extracted_text)\n```\n\n---\n\n### ✔️ **Extract Text from a Local Image**\n\n```python\nlocal_image_path = \"image.png\"\nimage_base64 = image_to_base64(local_image_path)\n\ntext = image_to_text_from_base64(image_base64)\nprint(text)\n```\n\n---\n\n## 🗂️ **Functions Overview**\n\n### **`image_to_base64(image_path)`**\n\nConverts local image → Base64 string.\n\n### **`image_to_text_from_url(image_url)`**\n\nSends URL directly to the LLM and extracts text.\n\n### **`image_to_text_from_base64(image_base64)`**\n\nSends Base64-encoded image to the LLM vision endpoint.\n\n---\n\n## 🔄 **Model-Agnostic Design**\n\nJust change one line:\n\n```python\nmodel=\"gpt-4o-mini\"\n```\n\nto:\n\n```python\nmodel=\"llama-3.2-vision\"\n# or\nmodel=\"gpt-4o\"\n# or\nmodel=\"groq-vision-preview\"\n# or\nmodel=\"any-supported-model\"\n```\n\nNo other code changes needed!\n\n---\n\n## 📌 **Use Cases**\n\n* Invoice/receipt text extraction\n* Handwritten notes to digital text\n* OCR for PDFs (after converting PDF → image)\n* Dataset preparation\n* Document summarization via OCR\n\n---\n\n## 🤝 Contributing\n\nIssues and pull requests are welcome.\nYou can extend this to PDF OCR, batch processing, or JSON structured output.\n\n---\n\n## 📄 License\n\nMIT License — free to use and modify.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceodaniyal%2Funiversal-llm-ocr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceodaniyal%2Funiversal-llm-ocr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceodaniyal%2Funiversal-llm-ocr/lists"}