Spaces:
Sleeping
Sleeping
chinna vemareddy commited on
Commit ·
ec16b53
1
Parent(s): 173d3c4
updated files
Browse files- .dockerignore +1 -0
- .gitignore +1 -1
- notebooks/01_exploration.ipynb +0 -0
- notebooks/02_evaluation.ipynb +297 -0
.dockerignore
CHANGED
|
@@ -12,6 +12,7 @@ venv/
|
|
| 12 |
.env
|
| 13 |
|
| 14 |
# Generated / runtime files
|
|
|
|
| 15 |
uploads/
|
| 16 |
*.pdf
|
| 17 |
*.png
|
|
|
|
| 12 |
.env
|
| 13 |
|
| 14 |
# Generated / runtime files
|
| 15 |
+
uploadss/
|
| 16 |
uploads/
|
| 17 |
*.pdf
|
| 18 |
*.png
|
.gitignore
CHANGED
|
@@ -87,7 +87,7 @@ logs/
|
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
-
|
| 91 |
uploads/
|
| 92 |
.env
|
| 93 |
__pycache__/
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
+
uploadss/
|
| 91 |
uploads/
|
| 92 |
.env
|
| 93 |
__pycache__/
|
notebooks/01_exploration.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/02_evaluation.ipynb
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "c13052bd",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"# 02_evaluation.ipynb\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"## Purpose\n",
|
| 13 |
+
"\"\"\"\n",
|
| 14 |
+
"This notebook performs lightweight automated evaluation of the DocVision\n",
|
| 15 |
+
"pipeline by validating output structure, rule-based constraints, and\n",
|
| 16 |
+
"measuring latency. It complements the declarative experiments defined\n",
|
| 17 |
+
"in the experiments/ directory.\n",
|
| 18 |
+
"\"\"\""
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"cell_type": "code",
|
| 23 |
+
"execution_count": 2,
|
| 24 |
+
"id": "3956698b",
|
| 25 |
+
"metadata": {},
|
| 26 |
+
"outputs": [],
|
| 27 |
+
"source": [
|
| 28 |
+
"import sys\n",
|
| 29 |
+
"import os\n",
|
| 30 |
+
"\n",
|
| 31 |
+
"PROJECT_ROOT = os.path.abspath(os.path.join(os.getcwd(), \"..\"))\n",
|
| 32 |
+
"if PROJECT_ROOT not in sys.path:\n",
|
| 33 |
+
" sys.path.append(PROJECT_ROOT)\n"
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"cell_type": "code",
|
| 38 |
+
"execution_count": 12,
|
| 39 |
+
"id": "765c2d64",
|
| 40 |
+
"metadata": {},
|
| 41 |
+
"outputs": [],
|
| 42 |
+
"source": [
|
| 43 |
+
"import os\n",
|
| 44 |
+
"import re\n",
|
| 45 |
+
"import time\n",
|
| 46 |
+
"import asyncio\n",
|
| 47 |
+
"from pprint import pprint\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"from src.vision import classify_image\n",
|
| 50 |
+
"from src.textextraction import extract_text_from_image_async\n"
|
| 51 |
+
]
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"cell_type": "code",
|
| 55 |
+
"execution_count": 5,
|
| 56 |
+
"id": "075c73df",
|
| 57 |
+
"metadata": {},
|
| 58 |
+
"outputs": [
|
| 59 |
+
{
|
| 60 |
+
"name": "stdout",
|
| 61 |
+
"output_type": "stream",
|
| 62 |
+
"text": [
|
| 63 |
+
"Evaluation files loaded: 2\n"
|
| 64 |
+
]
|
| 65 |
+
}
|
| 66 |
+
],
|
| 67 |
+
"source": [
|
| 68 |
+
"EVAL_FILES = [\n",
|
| 69 |
+
" \"C:/Users/bplsy/Documents/DOCVISION_IQ/notebooks/uploadss/driving license .jpg\",\n",
|
| 70 |
+
" \"C:/Users/bplsy/Documents/DOCVISION_IQ/notebooks/uploadss/ss.jpg\"\n",
|
| 71 |
+
"]\n",
|
| 72 |
+
"\n",
|
| 73 |
+
"for f in EVAL_FILES:\n",
|
| 74 |
+
" assert os.path.exists(f), f\"Missing file: {f}\"\n",
|
| 75 |
+
"\n",
|
| 76 |
+
"print(\"Evaluation files loaded:\", len(EVAL_FILES))\n"
|
| 77 |
+
]
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"cell_type": "code",
|
| 81 |
+
"execution_count": 13,
|
| 82 |
+
"id": "c94ff0d5",
|
| 83 |
+
"metadata": {},
|
| 84 |
+
"outputs": [],
|
| 85 |
+
"source": [
|
| 86 |
+
"async def evaluate_file(path: str):\n",
|
| 87 |
+
" start = time.time()\n",
|
| 88 |
+
"\n",
|
| 89 |
+
" # Run OCR explicitly for evaluation\n",
|
| 90 |
+
" ocr_text = await extract_text_from_image_async(path)\n",
|
| 91 |
+
"\n",
|
| 92 |
+
" # Run Vision LLM classification\n",
|
| 93 |
+
" result = await classify_image(path)\n",
|
| 94 |
+
"\n",
|
| 95 |
+
" latency = round(time.time() - start, 2)\n",
|
| 96 |
+
"\n",
|
| 97 |
+
" checks = {\n",
|
| 98 |
+
" \"valid_json\": all(\n",
|
| 99 |
+
" k in result for k in [\"document_type\", \"reasoning\", \"extracted_textfields\"]\n",
|
| 100 |
+
" ),\n",
|
| 101 |
+
" \"latency_sec\": latency,\n",
|
| 102 |
+
" }\n",
|
| 103 |
+
"\n",
|
| 104 |
+
" # ✅ CORRECT Aadhaar rule\n",
|
| 105 |
+
" if result[\"document_type\"] == \"aadhaar_card\":\n",
|
| 106 |
+
" checks[\"aadhaar_rule_passed\"] = bool(\n",
|
| 107 |
+
" re.search(r\"\\b\\d{12}\\b\", ocr_text) or \"UIDAI\" in ocr_text.upper()\n",
|
| 108 |
+
" )\n",
|
| 109 |
+
" else:\n",
|
| 110 |
+
" checks[\"aadhaar_rule_passed\"] = \"N/A\"\n",
|
| 111 |
+
"\n",
|
| 112 |
+
" return result, checks\n"
|
| 113 |
+
]
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"cell_type": "code",
|
| 117 |
+
"execution_count": 14,
|
| 118 |
+
"id": "1a8d83ed",
|
| 119 |
+
"metadata": {},
|
| 120 |
+
"outputs": [
|
| 121 |
+
{
|
| 122 |
+
"name": "stdout",
|
| 123 |
+
"output_type": "stream",
|
| 124 |
+
"text": [
|
| 125 |
+
"\n",
|
| 126 |
+
"Evaluating: C:/Users/bplsy/Documents/DOCVISION_IQ/notebooks/uploadss/driving license .jpg\n"
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"name": "stderr",
|
| 131 |
+
"output_type": "stream",
|
| 132 |
+
"text": [
|
| 133 |
+
"2026-01-29 13:04:45,587 - INFO - HTTP Request: POST https://api.cloud.llamaindex.ai/api/parsing/upload \"HTTP/1.1 200 OK\"\n"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"name": "stdout",
|
| 138 |
+
"output_type": "stream",
|
| 139 |
+
"text": [
|
| 140 |
+
"Started parsing the file under job_id 8dc83a68-9209-4b25-a474-e4be84fc7aaf\n"
|
| 141 |
+
]
|
| 142 |
+
},
|
| 143 |
+
{
|
| 144 |
+
"name": "stderr",
|
| 145 |
+
"output_type": "stream",
|
| 146 |
+
"text": [
|
| 147 |
+
"2026-01-29 13:04:46,942 - INFO - HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/8dc83a68-9209-4b25-a474-e4be84fc7aaf \"HTTP/1.1 200 OK\"\n",
|
| 148 |
+
"2026-01-29 13:04:49,232 - INFO - HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/8dc83a68-9209-4b25-a474-e4be84fc7aaf \"HTTP/1.1 200 OK\"\n",
|
| 149 |
+
"2026-01-29 13:04:49,626 - INFO - HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/8dc83a68-9209-4b25-a474-e4be84fc7aaf/result/text \"HTTP/1.1 200 OK\"\n"
|
| 150 |
+
]
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"name": "stdout",
|
| 154 |
+
"output_type": "stream",
|
| 155 |
+
"text": [
|
| 156 |
+
"Error while parsing the file '<bytes/buffer>': Event loop is closed\n"
|
| 157 |
+
]
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"name": "stderr",
|
| 161 |
+
"output_type": "stream",
|
| 162 |
+
"text": [
|
| 163 |
+
"2026-01-29 13:04:52,313 - INFO - HTTP Request: POST https://openrouter.ai/api/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 164 |
+
]
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"name": "stdout",
|
| 168 |
+
"output_type": "stream",
|
| 169 |
+
"text": [
|
| 170 |
+
"\n",
|
| 171 |
+
"Evaluating: C:/Users/bplsy/Documents/DOCVISION_IQ/notebooks/uploadss/ss.jpg\n"
|
| 172 |
+
]
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"name": "stderr",
|
| 176 |
+
"output_type": "stream",
|
| 177 |
+
"text": [
|
| 178 |
+
"2026-01-29 13:05:04,679 - INFO - HTTP Request: POST https://api.cloud.llamaindex.ai/api/parsing/upload \"HTTP/1.1 200 OK\"\n"
|
| 179 |
+
]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"name": "stdout",
|
| 183 |
+
"output_type": "stream",
|
| 184 |
+
"text": [
|
| 185 |
+
"Started parsing the file under job_id da70766a-4bf1-4341-9beb-3bbe4068374f\n"
|
| 186 |
+
]
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"name": "stderr",
|
| 190 |
+
"output_type": "stream",
|
| 191 |
+
"text": [
|
| 192 |
+
"2026-01-29 13:05:05,961 - INFO - HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/da70766a-4bf1-4341-9beb-3bbe4068374f \"HTTP/1.1 200 OK\"\n",
|
| 193 |
+
"2026-01-29 13:05:08,212 - INFO - HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/da70766a-4bf1-4341-9beb-3bbe4068374f \"HTTP/1.1 200 OK\"\n",
|
| 194 |
+
"2026-01-29 13:05:08,584 - INFO - HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/da70766a-4bf1-4341-9beb-3bbe4068374f/result/text \"HTTP/1.1 200 OK\"\n"
|
| 195 |
+
]
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
"name": "stdout",
|
| 199 |
+
"output_type": "stream",
|
| 200 |
+
"text": [
|
| 201 |
+
"Error while parsing the file '<bytes/buffer>': Event loop is closed\n"
|
| 202 |
+
]
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"name": "stderr",
|
| 206 |
+
"output_type": "stream",
|
| 207 |
+
"text": [
|
| 208 |
+
"2026-01-29 13:05:09,971 - INFO - HTTP Request: POST https://openrouter.ai/api/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 209 |
+
]
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"name": "stdout",
|
| 213 |
+
"output_type": "stream",
|
| 214 |
+
"text": [
|
| 215 |
+
"C:/Users/bplsy/Documents/DOCVISION_IQ/notebooks/uploadss/driving license .jpg\n",
|
| 216 |
+
"{'aadhaar_rule_passed': 'N/A', 'latency_sec': 19.71, 'valid_json': True}\n",
|
| 217 |
+
"C:/Users/bplsy/Documents/DOCVISION_IQ/notebooks/uploadss/ss.jpg\n",
|
| 218 |
+
"{'aadhaar_rule_passed': True, 'latency_sec': 13.3, 'valid_json': True}\n"
|
| 219 |
+
]
|
| 220 |
+
}
|
| 221 |
+
],
|
| 222 |
+
"source": [
|
| 223 |
+
"results = await evaluate_all(EVAL_FILES)\n",
|
| 224 |
+
"\n",
|
| 225 |
+
"for file, metrics in results:\n",
|
| 226 |
+
" print(file)\n",
|
| 227 |
+
" pprint(metrics)\n",
|
| 228 |
+
"\n"
|
| 229 |
+
]
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"cell_type": "code",
|
| 233 |
+
"execution_count": 15,
|
| 234 |
+
"id": "9738f8cc",
|
| 235 |
+
"metadata": {},
|
| 236 |
+
"outputs": [
|
| 237 |
+
{
|
| 238 |
+
"name": "stdout",
|
| 239 |
+
"output_type": "stream",
|
| 240 |
+
"text": [
|
| 241 |
+
"All evaluations completed successfully.\n"
|
| 242 |
+
]
|
| 243 |
+
}
|
| 244 |
+
],
|
| 245 |
+
"source": [
|
| 246 |
+
"print(\"All evaluations completed successfully.\")\n"
|
| 247 |
+
]
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"cell_type": "code",
|
| 251 |
+
"execution_count": 16,
|
| 252 |
+
"id": "907d8ab3",
|
| 253 |
+
"metadata": {},
|
| 254 |
+
"outputs": [
|
| 255 |
+
{
|
| 256 |
+
"data": {
|
| 257 |
+
"text/plain": [
|
| 258 |
+
"'\\nThis notebook demonstrates automated evaluation of DocVision outputs,\\nincluding JSON validity, rule-based constraints, and latency measurement.\\nResults support the evaluation protocol described in the README.\\n'"
|
| 259 |
+
]
|
| 260 |
+
},
|
| 261 |
+
"execution_count": 16,
|
| 262 |
+
"metadata": {},
|
| 263 |
+
"output_type": "execute_result"
|
| 264 |
+
}
|
| 265 |
+
],
|
| 266 |
+
"source": [
|
| 267 |
+
"## Summary\n",
|
| 268 |
+
"\"\"\"\n",
|
| 269 |
+
"This notebook demonstrates automated evaluation of DocVision outputs,\n",
|
| 270 |
+
"including JSON validity, rule-based constraints, and latency measurement.\n",
|
| 271 |
+
"Results support the evaluation protocol described in the README.\n",
|
| 272 |
+
"\"\"\"\n"
|
| 273 |
+
]
|
| 274 |
+
}
|
| 275 |
+
],
|
| 276 |
+
"metadata": {
|
| 277 |
+
"kernelspec": {
|
| 278 |
+
"display_name": ".venv",
|
| 279 |
+
"language": "python",
|
| 280 |
+
"name": "python3"
|
| 281 |
+
},
|
| 282 |
+
"language_info": {
|
| 283 |
+
"codemirror_mode": {
|
| 284 |
+
"name": "ipython",
|
| 285 |
+
"version": 3
|
| 286 |
+
},
|
| 287 |
+
"file_extension": ".py",
|
| 288 |
+
"mimetype": "text/x-python",
|
| 289 |
+
"name": "python",
|
| 290 |
+
"nbconvert_exporter": "python",
|
| 291 |
+
"pygments_lexer": "ipython3",
|
| 292 |
+
"version": "3.13.5"
|
| 293 |
+
}
|
| 294 |
+
},
|
| 295 |
+
"nbformat": 4,
|
| 296 |
+
"nbformat_minor": 5
|
| 297 |
+
}
|