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
|
13 |
+
"name": "python"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"cells": [
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"source": [
|
20 |
+
"!pip install openai==0.28"
|
21 |
+
],
|
22 |
+
"metadata": {
|
23 |
+
"colab": {
|
24 |
+
"base_uri": "https://localhost:8080/"
|
25 |
+
},
|
26 |
+
"id": "ROE6pVjqkT-L",
|
27 |
+
"outputId": "01c9f4da-81a9-43ed-c3ac-572e96880a2b"
|
28 |
+
},
|
29 |
+
"execution_count": 1,
|
30 |
+
"outputs": [
|
31 |
+
{
|
32 |
+
"output_type": "stream",
|
33 |
+
"name": "stdout",
|
34 |
+
"text": [
|
35 |
+
"Collecting openai==0.28\n",
|
36 |
+
" Downloading openai-0.28.0-py3-none-any.whl.metadata (13 kB)\n",
|
37 |
+
"Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.11/dist-packages (from openai==0.28) (2.32.3)\n",
|
38 |
+
"Requirement already satisfied: tqdm in /usr/local/lib/python3.11/dist-packages (from openai==0.28) (4.67.1)\n",
|
39 |
+
"Requirement already satisfied: aiohttp in /usr/local/lib/python3.11/dist-packages (from openai==0.28) (3.11.11)\n",
|
40 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.20->openai==0.28) (3.4.1)\n",
|
41 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.20->openai==0.28) (3.10)\n",
|
42 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.20->openai==0.28) (2.3.0)\n",
|
43 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=2.20->openai==0.28) (2024.12.14)\n",
|
44 |
+
"Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (2.4.4)\n",
|
45 |
+
"Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (1.3.2)\n",
|
46 |
+
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (25.1.0)\n",
|
47 |
+
"Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (1.5.0)\n",
|
48 |
+
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (6.1.0)\n",
|
49 |
+
"Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (0.2.1)\n",
|
50 |
+
"Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->openai==0.28) (1.18.3)\n",
|
51 |
+
"Downloading openai-0.28.0-py3-none-any.whl (76 kB)\n",
|
52 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.5/76.5 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
53 |
+
"\u001b[?25hInstalling collected packages: openai\n",
|
54 |
+
" Attempting uninstall: openai\n",
|
55 |
+
" Found existing installation: openai 1.59.9\n",
|
56 |
+
" Uninstalling openai-1.59.9:\n",
|
57 |
+
" Successfully uninstalled openai-1.59.9\n",
|
58 |
+
"Successfully installed openai-0.28.0\n"
|
59 |
+
]
|
60 |
+
}
|
61 |
+
]
|
62 |
+
},
|
63 |
+
{
|
64 |
+
"cell_type": "code",
|
65 |
+
"source": [
|
66 |
+
"!pip install pdf2image\n",
|
67 |
+
"!sudo apt-get install poppler-utils\n"
|
68 |
+
],
|
69 |
+
"metadata": {
|
70 |
+
"colab": {
|
71 |
+
"base_uri": "https://localhost:8080/"
|
72 |
+
},
|
73 |
+
"id": "-QwkjUM-lCOS",
|
74 |
+
"outputId": "02d87d12-9026-4601-a3ad-f92ea74c3a6c"
|
75 |
+
},
|
76 |
+
"execution_count": 2,
|
77 |
+
"outputs": [
|
78 |
+
{
|
79 |
+
"output_type": "stream",
|
80 |
+
"name": "stdout",
|
81 |
+
"text": [
|
82 |
+
"Collecting pdf2image\n",
|
83 |
+
" Downloading pdf2image-1.17.0-py3-none-any.whl.metadata (6.2 kB)\n",
|
84 |
+
"Requirement already satisfied: pillow in /usr/local/lib/python3.11/dist-packages (from pdf2image) (11.1.0)\n",
|
85 |
+
"Downloading pdf2image-1.17.0-py3-none-any.whl (11 kB)\n",
|
86 |
+
"Installing collected packages: pdf2image\n",
|
87 |
+
"Successfully installed pdf2image-1.17.0\n",
|
88 |
+
"Reading package lists... Done\n",
|
89 |
+
"Building dependency tree... Done\n",
|
90 |
+
"Reading state information... Done\n",
|
91 |
+
"The following NEW packages will be installed:\n",
|
92 |
+
" poppler-utils\n",
|
93 |
+
"0 upgraded, 1 newly installed, 0 to remove and 18 not upgraded.\n",
|
94 |
+
"Need to get 186 kB of archives.\n",
|
95 |
+
"After this operation, 696 kB of additional disk space will be used.\n",
|
96 |
+
"Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 poppler-utils amd64 22.02.0-2ubuntu0.6 [186 kB]\n",
|
97 |
+
"Fetched 186 kB in 1s (260 kB/s)\n",
|
98 |
+
"debconf: unable to initialize frontend: Dialog\n",
|
99 |
+
"debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78, <> line 1.)\n",
|
100 |
+
"debconf: falling back to frontend: Readline\n",
|
101 |
+
"debconf: unable to initialize frontend: Readline\n",
|
102 |
+
"debconf: (This frontend requires a controlling tty.)\n",
|
103 |
+
"debconf: falling back to frontend: Teletype\n",
|
104 |
+
"dpkg-preconfigure: unable to re-open stdin: \n",
|
105 |
+
"Selecting previously unselected package poppler-utils.\n",
|
106 |
+
"(Reading database ... 124950 files and directories currently installed.)\n",
|
107 |
+
"Preparing to unpack .../poppler-utils_22.02.0-2ubuntu0.6_amd64.deb ...\n",
|
108 |
+
"Unpacking poppler-utils (22.02.0-2ubuntu0.6) ...\n",
|
109 |
+
"Setting up poppler-utils (22.02.0-2ubuntu0.6) ...\n",
|
110 |
+
"Processing triggers for man-db (2.10.2-1) ...\n"
|
111 |
+
]
|
112 |
+
}
|
113 |
+
]
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"cell_type": "code",
|
117 |
+
"source": [
|
118 |
+
"import openai\n",
|
119 |
+
"from pdf2image import convert_from_path\n",
|
120 |
+
"import json\n",
|
121 |
+
"import pandas as pd\n",
|
122 |
+
"import os\n",
|
123 |
+
"import base64\n",
|
124 |
+
"import re\n",
|
125 |
+
"\n",
|
126 |
+
"# OpenAI API Key\n",
|
127 |
+
"openai.api_key = \"key\"\n",
|
128 |
+
"\n",
|
129 |
+
"# Set Paths\n",
|
130 |
+
"pdf_path = \"/content/QB-MARATHI.pdf\"\n",
|
131 |
+
"source = \"https://transport.maharashtra.gov.in/Site/Upload/Pdf/QB-MARATHI.pdf\"\n",
|
132 |
+
"results_folder = \"/content/results\"\n",
|
133 |
+
"images_folder = os.path.join(results_folder, \"images\")\n",
|
134 |
+
"os.makedirs(results_folder, exist_ok=True)\n",
|
135 |
+
"os.makedirs(images_folder, exist_ok=True)\n",
|
136 |
+
"\n",
|
137 |
+
"# GPT Prompt\n",
|
138 |
+
"pre_prompt = \"\"\"Please extract the multiple-choice questions in the attached image in Marathi.\n",
|
139 |
+
"There can be one or multiple questions per page.\n",
|
140 |
+
"\n",
|
141 |
+
"Format the output as:\n",
|
142 |
+
"<question_num>Question Number</question_num>\n",
|
143 |
+
"<question>Question Text</question>\n",
|
144 |
+
"<choices>\n",
|
145 |
+
" <choice>A</choice>\n",
|
146 |
+
" <choice>B</choice>\n",
|
147 |
+
" <choice>C</choice>\n",
|
148 |
+
"</choices>\n",
|
149 |
+
"<answer>Correct Answer Index (1, 2, or 3)</answer>\n",
|
150 |
+
"<image>yes/no</image>\n",
|
151 |
+
"\n",
|
152 |
+
"IMPORTANT:\n",
|
153 |
+
"- The <answer> tag should contain ONLY a single integer: 1, 2, or 3.\n",
|
154 |
+
"- Do NOT include the actual answer text, only the index.\n",
|
155 |
+
"- If no answer is available, leave <answer></answer> empty.\n",
|
156 |
+
"- If the question has an associated image (diagram, symbol, road sign), respond with `<image>yes</image>`.\n",
|
157 |
+
"- Otherwise, respond with `<image>no</image>`.\n",
|
158 |
+
"- If the image contains a reference like 'चित्रात दाखवल्याप्रमाणे' (Marathi for \"as shown in the figure\"), ensure `<image>yes</image>`.\n",
|
159 |
+
"- Ensure options are unique and contain at least two valid choices.\n",
|
160 |
+
"\"\"\"\n",
|
161 |
+
"\n",
|
162 |
+
"# Convert PDF to Images\n",
|
163 |
+
"def convert_pdf_to_images(pdf_path):\n",
|
164 |
+
" print(\"📄 Converting PDF to Images...\")\n",
|
165 |
+
" images = convert_from_path(pdf_path, dpi=300)\n",
|
166 |
+
" image_paths = []\n",
|
167 |
+
"\n",
|
168 |
+
" for i, image in enumerate(images):\n",
|
169 |
+
" img_path = os.path.join(images_folder, f\"page_{i+1}.png\")\n",
|
170 |
+
" image.save(img_path, \"PNG\")\n",
|
171 |
+
" image_paths.append(img_path)\n",
|
172 |
+
"\n",
|
173 |
+
" print(f\"✅ {len(image_paths)} images saved.\")\n",
|
174 |
+
" return image_paths\n",
|
175 |
+
"\n",
|
176 |
+
"# Encode Image in Base64\n",
|
177 |
+
"def encode_image(image_path):\n",
|
178 |
+
" with open(image_path, \"rb\") as image_file:\n",
|
179 |
+
" return base64.b64encode(image_file.read()).decode(\"utf-8\")\n",
|
180 |
+
"\n",
|
181 |
+
"# Process Image with GPT-4o\n",
|
182 |
+
"def gpt4o_process_image(image_path):\n",
|
183 |
+
" base64_image = encode_image(image_path)\n",
|
184 |
+
"\n",
|
185 |
+
" try:\n",
|
186 |
+
" response = openai.ChatCompletion.create(\n",
|
187 |
+
" model=\"gpt-4o\",\n",
|
188 |
+
" messages=[\n",
|
189 |
+
" {\"role\": \"system\", \"content\": pre_prompt},\n",
|
190 |
+
" {\"role\": \"user\", \"content\": [\n",
|
191 |
+
" {\"type\": \"text\", \"text\": \"Extract all questions from this image.\"},\n",
|
192 |
+
" {\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{base64_image}\"}}\n",
|
193 |
+
" ]}\n",
|
194 |
+
" ],\n",
|
195 |
+
" max_tokens=2000\n",
|
196 |
+
" )\n",
|
197 |
+
"\n",
|
198 |
+
" extracted_text = response[\"choices\"][0][\"message\"][\"content\"]\n",
|
199 |
+
" return extracted_text\n",
|
200 |
+
"\n",
|
201 |
+
" except json.JSONDecodeError:\n",
|
202 |
+
" print(\"❌ Error: GPT-4o returned an invalid JSON format.\")\n",
|
203 |
+
" return None\n",
|
204 |
+
"\n",
|
205 |
+
"# Parse GPT Response & Fix Issues\n",
|
206 |
+
"def parse_gpt_output(response):\n",
|
207 |
+
" # Regex patterns for structured extraction\n",
|
208 |
+
" q_num_pattern = re.compile(r\"<question_num>(\\d+)</question_num>\")\n",
|
209 |
+
" q_pattern = re.compile(r\"<question>(.*?)</question>\")\n",
|
210 |
+
" choices_pattern = re.compile(r\"<choices>(.*?)</choices>\", re.DOTALL)\n",
|
211 |
+
" answer_pattern = re.compile(r\"<answer>(.*?)</answer>\")\n",
|
212 |
+
" image_pattern = re.compile(r\"<image>(.*?)</image>\")\n",
|
213 |
+
"\n",
|
214 |
+
" # Extract values\n",
|
215 |
+
" question_nums = q_num_pattern.findall(response)\n",
|
216 |
+
" questions = q_pattern.findall(response)\n",
|
217 |
+
" choices_raw = choices_pattern.findall(response)\n",
|
218 |
+
" answers_raw = answer_pattern.findall(response)\n",
|
219 |
+
" images_required = image_pattern.findall(response)\n",
|
220 |
+
"\n",
|
221 |
+
" # Extract choices correctly & ensure uniqueness\n",
|
222 |
+
" choices = []\n",
|
223 |
+
" for choice_text in choices_raw:\n",
|
224 |
+
" extracted_choices = list(set(re.findall(r\"<choice>(.*?)</choice>\", choice_text))) # Ensure unique choices\n",
|
225 |
+
" if len(extracted_choices) < 2: # Validator requires at least two options\n",
|
226 |
+
" extracted_choices.append(\"Option Placeholder\") # Add dummy placeholder\n",
|
227 |
+
" choices.append(extracted_choices)\n",
|
228 |
+
"\n",
|
229 |
+
" # Convert to integer (1,2,3) and validate range\n",
|
230 |
+
" valid_answers = []\n",
|
231 |
+
" for answer in answers_raw:\n",
|
232 |
+
" try:\n",
|
233 |
+
" int_answer = int(answer.strip())\n",
|
234 |
+
" if 1 <= int_answer <= 3: # Ensure valid 1-based index\n",
|
235 |
+
" valid_answers.append(int_answer)\n",
|
236 |
+
" else:\n",
|
237 |
+
" valid_answers.append(None)\n",
|
238 |
+
" except ValueError:\n",
|
239 |
+
" valid_answers.append(None)\n",
|
240 |
+
"\n",
|
241 |
+
" # Ensure all lists have the same length\n",
|
242 |
+
" min_length = min(len(question_nums), len(questions), len(choices), len(valid_answers), len(images_required))\n",
|
243 |
+
" question_nums = question_nums[:min_length]\n",
|
244 |
+
" questions = questions[:min_length]\n",
|
245 |
+
" choices = choices[:min_length]\n",
|
246 |
+
" valid_answers = valid_answers[:min_length]\n",
|
247 |
+
" images_required = images_required[:min_length]\n",
|
248 |
+
"\n",
|
249 |
+
" return question_nums, questions, choices, valid_answers, images_required\n",
|
250 |
+
"\n",
|
251 |
+
"# Main Execution\n",
|
252 |
+
"def main():\n",
|
253 |
+
" image_paths = convert_pdf_to_images(pdf_path)\n",
|
254 |
+
" all_questions = []\n",
|
255 |
+
"\n",
|
256 |
+
" for img_path in image_paths:\n",
|
257 |
+
" print(f\"📷 Processing {img_path}...\")\n",
|
258 |
+
" response = gpt4o_process_image(img_path)\n",
|
259 |
+
"\n",
|
260 |
+
" if response:\n",
|
261 |
+
" q_nums, q_texts, options, correct_answers, images_required = parse_gpt_output(response)\n",
|
262 |
+
"\n",
|
263 |
+
" for i in range(len(q_nums)):\n",
|
264 |
+
" image_info = None\n",
|
265 |
+
" image_png = None\n",
|
266 |
+
" image_type = None\n",
|
267 |
+
"\n",
|
268 |
+
" if images_required[i] == \"yes\":\n",
|
269 |
+
" image_png = f\"driving-license-marathi-{q_nums[i]}.png\"\n",
|
270 |
+
" image_info = \"essential\"\n",
|
271 |
+
" image_type = \"diagram\"\n",
|
272 |
+
"\n",
|
273 |
+
" question_data = {\n",
|
274 |
+
" \"language\": \"mr\",\n",
|
275 |
+
" \"country\": \"India\",\n",
|
276 |
+
" \"file_name\": \"QB-MARATHI.pdf\",\n",
|
277 |
+
" \"source\": source,\n",
|
278 |
+
" \"license\": \"Education and Research\",\n",
|
279 |
+
" \"level\": \"Driver License\",\n",
|
280 |
+
" \"category_en\": \"Driving\",\n",
|
281 |
+
" \"category_original_lang\": \"ड्रायव्हिंग\",\n",
|
282 |
+
" \"original_question_num\": int(q_nums[i]),\n",
|
283 |
+
" \"question\": q_texts[i],\n",
|
284 |
+
" \"options\": options[i] if i < len(options) else [],\n",
|
285 |
+
" \"answer\": correct_answers[i], # ✅ Always 1,2,3\n",
|
286 |
+
" \"image_png\": image_png,\n",
|
287 |
+
" \"image_information\": image_info,\n",
|
288 |
+
" \"image_type\": image_type,\n",
|
289 |
+
" \"parallel_question_id\": None\n",
|
290 |
+
" }\n",
|
291 |
+
" all_questions.append(question_data)\n",
|
292 |
+
"\n",
|
293 |
+
" # Save as JSON\n",
|
294 |
+
" json_path = os.path.join(results_folder, \"marathi_driving_license_valid.json\")\n",
|
295 |
+
" with open(json_path, \"w\", encoding=\"utf-8\") as f:\n",
|
296 |
+
" json.dump(all_questions, f, indent=4, ensure_ascii=False)\n",
|
297 |
+
"\n",
|
298 |
+
" # Convert to CSV\n",
|
299 |
+
" df = pd.DataFrame(all_questions)\n",
|
300 |
+
" csv_path = os.path.join(results_folder, \"marathi_driving_license_valid.csv\")\n",
|
301 |
+
" df.to_csv(csv_path, index=False, encoding=\"utf-8\")\n",
|
302 |
+
"\n",
|
303 |
+
" print(f\"✅ JSON Saved: {json_path}\")\n",
|
304 |
+
" print(f\"✅ CSV Saved: {csv_path}\")\n",
|
305 |
+
"\n",
|
306 |
+
"# Run the script\n",
|
307 |
+
"main()\n"
|
308 |
+
],
|
309 |
+
"metadata": {
|
310 |
+
"colab": {
|
311 |
+
"base_uri": "https://localhost:8080/"
|
312 |
+
},
|
313 |
+
"id": "OgERpYUuTV8k",
|
314 |
+
"outputId": "b67d003f-5647-45e5-9632-46ae8b10c510"
|
315 |
+
},
|
316 |
+
"execution_count": 4,
|
317 |
+
"outputs": [
|
318 |
+
{
|
319 |
+
"output_type": "stream",
|
320 |
+
"name": "stdout",
|
321 |
+
"text": [
|
322 |
+
"📄 Converting PDF to Images...\n",
|
323 |
+
"✅ 107 images saved.\n",
|
324 |
+
"📷 Processing /content/results/images/page_1.png...\n",
|
325 |
+
"📷 Processing /content/results/images/page_2.png...\n",
|
326 |
+
"📷 Processing /content/results/images/page_3.png...\n",
|
327 |
+
"📷 Processing /content/results/images/page_4.png...\n",
|
328 |
+
"📷 Processing /content/results/images/page_5.png...\n",
|
329 |
+
"📷 Processing /content/results/images/page_6.png...\n",
|
330 |
+
"📷 Processing /content/results/images/page_7.png...\n",
|
331 |
+
"📷 Processing /content/results/images/page_8.png...\n",
|
332 |
+
"📷 Processing /content/results/images/page_9.png...\n",
|
333 |
+
"📷 Processing /content/results/images/page_10.png...\n",
|
334 |
+
"📷 Processing /content/results/images/page_11.png...\n",
|
335 |
+
"📷 Processing /content/results/images/page_12.png...\n",
|
336 |
+
"📷 Processing /content/results/images/page_13.png...\n",
|
337 |
+
"📷 Processing /content/results/images/page_14.png...\n",
|
338 |
+
"📷 Processing /content/results/images/page_15.png...\n",
|
339 |
+
"📷 Processing /content/results/images/page_16.png...\n",
|
340 |
+
"📷 Processing /content/results/images/page_17.png...\n",
|
341 |
+
"📷 Processing /content/results/images/page_18.png...\n",
|
342 |
+
"📷 Processing /content/results/images/page_19.png...\n",
|
343 |
+
"📷 Processing /content/results/images/page_20.png...\n",
|
344 |
+
"📷 Processing /content/results/images/page_21.png...\n",
|
345 |
+
"📷 Processing /content/results/images/page_22.png...\n",
|
346 |
+
"📷 Processing /content/results/images/page_23.png...\n",
|
347 |
+
"📷 Processing /content/results/images/page_24.png...\n",
|
348 |
+
"📷 Processing /content/results/images/page_25.png...\n",
|
349 |
+
"📷 Processing /content/results/images/page_26.png...\n",
|
350 |
+
"📷 Processing /content/results/images/page_27.png...\n",
|
351 |
+
"📷 Processing /content/results/images/page_28.png...\n",
|
352 |
+
"📷 Processing /content/results/images/page_29.png...\n",
|
353 |
+
"📷 Processing /content/results/images/page_30.png...\n",
|
354 |
+
"📷 Processing /content/results/images/page_31.png...\n",
|
355 |
+
"📷 Processing /content/results/images/page_32.png...\n",
|
356 |
+
"📷 Processing /content/results/images/page_33.png...\n",
|
357 |
+
"📷 Processing /content/results/images/page_34.png...\n",
|
358 |
+
"📷 Processing /content/results/images/page_35.png...\n",
|
359 |
+
"📷 Processing /content/results/images/page_36.png...\n",
|
360 |
+
"📷 Processing /content/results/images/page_37.png...\n",
|
361 |
+
"📷 Processing /content/results/images/page_38.png...\n",
|
362 |
+
"📷 Processing /content/results/images/page_39.png...\n",
|
363 |
+
"📷 Processing /content/results/images/page_40.png...\n",
|
364 |
+
"📷 Processing /content/results/images/page_41.png...\n",
|
365 |
+
"📷 Processing /content/results/images/page_42.png...\n",
|
366 |
+
"📷 Processing /content/results/images/page_43.png...\n",
|
367 |
+
"📷 Processing /content/results/images/page_44.png...\n",
|
368 |
+
"📷 Processing /content/results/images/page_45.png...\n",
|
369 |
+
"📷 Processing /content/results/images/page_46.png...\n",
|
370 |
+
"📷 Processing /content/results/images/page_47.png...\n",
|
371 |
+
"📷 Processing /content/results/images/page_48.png...\n",
|
372 |
+
"📷 Processing /content/results/images/page_49.png...\n",
|
373 |
+
"📷 Processing /content/results/images/page_50.png...\n",
|
374 |
+
"📷 Processing /content/results/images/page_51.png...\n",
|
375 |
+
"📷 Processing /content/results/images/page_52.png...\n",
|
376 |
+
"📷 Processing /content/results/images/page_53.png...\n",
|
377 |
+
"📷 Processing /content/results/images/page_54.png...\n",
|
378 |
+
"📷 Processing /content/results/images/page_55.png...\n",
|
379 |
+
"📷 Processing /content/results/images/page_56.png...\n",
|
380 |
+
"📷 Processing /content/results/images/page_57.png...\n",
|
381 |
+
"📷 Processing /content/results/images/page_58.png...\n",
|
382 |
+
"📷 Processing /content/results/images/page_59.png...\n",
|
383 |
+
"📷 Processing /content/results/images/page_60.png...\n",
|
384 |
+
"📷 Processing /content/results/images/page_61.png...\n",
|
385 |
+
"📷 Processing /content/results/images/page_62.png...\n",
|
386 |
+
"📷 Processing /content/results/images/page_63.png...\n",
|
387 |
+
"📷 Processing /content/results/images/page_64.png...\n",
|
388 |
+
"📷 Processing /content/results/images/page_65.png...\n",
|
389 |
+
"📷 Processing /content/results/images/page_66.png...\n",
|
390 |
+
"📷 Processing /content/results/images/page_67.png...\n",
|
391 |
+
"📷 Processing /content/results/images/page_68.png...\n",
|
392 |
+
"📷 Processing /content/results/images/page_69.png...\n",
|
393 |
+
"📷 Processing /content/results/images/page_70.png...\n",
|
394 |
+
"📷 Processing /content/results/images/page_71.png...\n",
|
395 |
+
"📷 Processing /content/results/images/page_72.png...\n",
|
396 |
+
"📷 Processing /content/results/images/page_73.png...\n",
|
397 |
+
"📷 Processing /content/results/images/page_74.png...\n",
|
398 |
+
"📷 Processing /content/results/images/page_75.png...\n",
|
399 |
+
"📷 Processing /content/results/images/page_76.png...\n",
|
400 |
+
"📷 Processing /content/results/images/page_77.png...\n",
|
401 |
+
"📷 Processing /content/results/images/page_78.png...\n",
|
402 |
+
"📷 Processing /content/results/images/page_79.png...\n",
|
403 |
+
"📷 Processing /content/results/images/page_80.png...\n",
|
404 |
+
"📷 Processing /content/results/images/page_81.png...\n",
|
405 |
+
"📷 Processing /content/results/images/page_82.png...\n",
|
406 |
+
"📷 Processing /content/results/images/page_83.png...\n",
|
407 |
+
"📷 Processing /content/results/images/page_84.png...\n",
|
408 |
+
"📷 Processing /content/results/images/page_85.png...\n",
|
409 |
+
"📷 Processing /content/results/images/page_86.png...\n",
|
410 |
+
"📷 Processing /content/results/images/page_87.png...\n",
|
411 |
+
"📷 Processing /content/results/images/page_88.png...\n",
|
412 |
+
"📷 Processing /content/results/images/page_89.png...\n",
|
413 |
+
"📷 Processing /content/results/images/page_90.png...\n",
|
414 |
+
"📷 Processing /content/results/images/page_91.png...\n",
|
415 |
+
"📷 Processing /content/results/images/page_92.png...\n",
|
416 |
+
"📷 Processing /content/results/images/page_93.png...\n",
|
417 |
+
"📷 Processing /content/results/images/page_94.png...\n",
|
418 |
+
"📷 Processing /content/results/images/page_95.png...\n",
|
419 |
+
"📷 Processing /content/results/images/page_96.png...\n",
|
420 |
+
"📷 Processing /content/results/images/page_97.png...\n",
|
421 |
+
"📷 Processing /content/results/images/page_98.png...\n",
|
422 |
+
"📷 Processing /content/results/images/page_99.png...\n",
|
423 |
+
"📷 Processing /content/results/images/page_100.png...\n",
|
424 |
+
"📷 Processing /content/results/images/page_101.png...\n",
|
425 |
+
"📷 Processing /content/results/images/page_102.png...\n",
|
426 |
+
"📷 Processing /content/results/images/page_103.png...\n",
|
427 |
+
"📷 Processing /content/results/images/page_104.png...\n",
|
428 |
+
"📷 Processing /content/results/images/page_105.png...\n",
|
429 |
+
"📷 Processing /content/results/images/page_106.png...\n",
|
430 |
+
"📷 Processing /content/results/images/page_107.png...\n",
|
431 |
+
"✅ JSON Saved: /content/results/QB-MARATHI_valid.json\n",
|
432 |
+
"✅ CSV Saved: /content/results/QB-MARATHI_valid.csv\n"
|
433 |
+
]
|
434 |
+
}
|
435 |
+
]
|
436 |
+
},
|
437 |
+
{
|
438 |
+
"cell_type": "code",
|
439 |
+
"source": [],
|
440 |
+
"metadata": {
|
441 |
+
"id": "tvQrB5J4Ue5Q"
|
442 |
+
},
|
443 |
+
"execution_count": null,
|
444 |
+
"outputs": []
|
445 |
+
}
|
446 |
+
]
|
447 |
+
}
|