A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.
audit: fix image_question_answering - add env comment, rewrite em dashes, add module docstring, add docstrings
Tiioluwani5bdbc4bf66cb
diff --git a/multimodal/image_question_answering/.env.example b/multimodal/image_question_answering/.env.exampleindex fa40a94..1fd7173 100644--- a/multimodal/image_question_answering/.env.example+++ b/multimodal/image_question_answering/.env.example@@ -1 +1,3 @@-GOOGLE_API_KEY=your_api_key_here+# Google AI Studio API key (required)+# Get your free key at https://aistudio.google.com+GOOGLE_API_KEY=your_api_key_herediff --git a/multimodal/image_question_answering/README.md b/multimodal/image_question_answering/README.mdindex 8d50626..a563026 100644--- a/multimodal/image_question_answering/README.md+++ b/multimodal/image_question_answering/README.md@@ -4,7 +4,7 @@## Overview-Upload a PDF, select a page, and ask a natural-language question about its visual content. PyMuPDF renders each page into a high-quality image, which is sent alongside your question to Gemma 4 (`gemma-4-31b-it`) via the Gemini API. The model reasons over the rendered image — including charts, tables, diagrams, and figures — and returns a grounded answer in the Gradio interface.+Upload a PDF, select a page, and ask a natural-language question about its visual content. PyMuPDF renders each page into a high-quality image, which is sent alongside your question to Gemma 4 (`gemma-4-31b-it`) via the Gemini API. The model reasons over the rendered image, including charts, tables, diagrams, and figures, and returns a grounded answer in the Gradio interface.## Demo@@ -16,7 +16,7 @@ Upload a PDF, select a page, and ask a natural-language question about its visua- Page slider lets you navigate and preview any page before asking- Answers visual questions grounded in the actual rendered content (charts, tables, figures)- Gemma 4 thinking mode (`high`) for multi-step reasoning over complex layouts-- Clean two-column Gradio UI — page viewer on the left, Q&A on the right+- Clean two-column Gradio UI with the page viewer on the left and Q&A on the right## Tech Stack@@ -88,7 +88,7 @@ Create a `.env` file in the project root with the following key:| Variable | Description ||---|---|-| `GOOGLE_API_KEY` | Gemini API key — obtain one at [aistudio.google.com](https://aistudio.google.com) |+| `GOOGLE_API_KEY` | Gemini API key; obtain one at [aistudio.google.com](https://aistudio.google.com) |```envGOOGLE_API_KEY=your_api_key_here@@ -103,3 +103,7 @@ image-question-answering/├── .env.example # Environment variable template└── requirements.txt```++---++[Back to Top](#image-question-answering)diff --git a/multimodal/image_question_answering/app.py b/multimodal/image_question_answering/app.pyindex 1919fb8..528fc24 100644--- a/multimodal/image_question_answering/app.py+++ b/multimodal/image_question_answering/app.py@@ -1,3 +1,5 @@+"""Image Question Answering: upload a PDF, select a page, and ask visual questions answered by Gemma 4 via the Gemini API."""+import ioimport os@@ -23,6 +25,7 @@ _page_images: list[Image.Image] = []def pdf_to_images(path: str, dpi: int = 150) -> list[Image.Image]:+ """Render every page of the PDF at the given DPI and return them as a list of PIL images."""doc = fitz.open(path)zoom = dpi / 72.0mat = fitz.Matrix(zoom, zoom)@@ -38,6 +41,7 @@ def pdf_to_images(path: str, dpi: int = 150) -> list[Image.Image]:def on_pdf_upload(pdf_file):+ """Handle a PDF upload by rendering all pages and initialising the page slider."""global _page_imagesif pdf_file is None:@@ -62,6 +66,7 @@ def on_pdf_upload(pdf_file):def on_page_change(page_num: int):+ """Return the PIL image for the selected 1-based page number."""idx = int(page_num) - 1if _page_images and 0 <= idx < len(_page_images):return _page_images[idx]@@ -69,6 +74,7 @@ def on_page_change(page_num: int):def on_submit(page_num: int, question: str):+ """Send the selected page image and question to Gemma 4 and return the answer text."""if not _page_images:return "Please upload a PDF first."if not question.strip():