File size: 34,641 Bytes
a1c8685
 
 
 
b4fe9b6
a1c8685
 
d053923
a1c8685
 
 
 
 
 
 
 
 
b4fe9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1c8685
 
 
 
 
 
 
 
 
b4fe9b6
a1c8685
 
 
 
 
 
 
 
 
 
 
b4fe9b6
a1c8685
 
d053923
a1c8685
2ae29dd
b4fe9b6
d053923
a1c8685
 
 
 
b4fe9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1c8685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4fe9b6
2ae29dd
a1c8685
 
 
b4fe9b6
2ae29dd
 
 
 
b4fe9b6
2ae29dd
 
 
 
 
 
a1c8685
2ae29dd
a1c8685
2ae29dd
 
 
 
 
a1c8685
2ae29dd
 
 
a1c8685
2ae29dd
 
 
 
a1c8685
2ae29dd
 
a1c8685
2ae29dd
 
 
 
 
a1c8685
2ae29dd
a1c8685
2ae29dd
 
 
 
 
a1c8685
2ae29dd
 
 
 
 
 
 
 
 
a1c8685
2ae29dd
 
a1c8685
 
 
 
b4fe9b6
a1c8685
 
 
 
 
 
 
2ae29dd
a1c8685
 
 
d053923
 
b4fe9b6
d053923
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4fe9b6
d053923
 
 
 
 
 
 
 
 
b4fe9b6
d053923
 
 
 
 
 
 
 
 
 
b4fe9b6
d053923
 
b4fe9b6
 
 
 
 
 
 
 
 
 
 
 
 
d053923
 
 
 
 
 
b4fe9b6
d053923
 
 
 
 
 
 
b4fe9b6
d053923
 
 
 
 
 
b4fe9b6
d053923
 
 
 
 
 
 
 
 
 
 
 
b4fe9b6
d053923
 
 
 
 
 
b4fe9b6
d053923
 
b4fe9b6
d053923
 
 
 
 
 
 
 
a1c8685
 
b4fe9b6
2ae29dd
 
 
 
 
 
 
 
 
b4fe9b6
a1c8685
 
 
 
 
 
 
 
 
b4fe9b6
a1c8685
 
 
 
 
 
 
 
 
 
 
b4fe9b6
2ae29dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4fe9b6
a1c8685
 
 
 
 
 
 
 
b4fe9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1c8685
b4fe9b6
a1c8685
 
 
 
 
 
d053923
b4fe9b6
 
a1c8685
 
b4fe9b6
a1c8685
 
 
 
 
b4fe9b6
a1c8685
 
 
 
 
b4fe9b6
 
 
 
 
 
 
 
 
a1c8685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4fe9b6
a1c8685
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "5223b1b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from web2json.preprocessor import *\n",
    "from web2json.ai_extractor import *\n",
    "from web2json.postprocessor import *\n",
    "from web2json.pipeline import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "5ccc96b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "def seed_everything(seed=42):\n",
    "    random.seed(seed)\n",
    "    np.random.seed(seed)\n",
    "    torch.manual_seed(seed)\n",
    "\n",
    "    if torch.cuda.is_available():\n",
    "        torch.cuda.manual_seed(seed)\n",
    "        torch.cuda.manual_seed_all(seed)  # if using multi-GPU\n",
    "\n",
    "    torch.backends.cudnn.deterministic = True\n",
    "    torch.backends.cudnn.benchmark = False\n",
    "\n",
    "seed_everything(44)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "ae4e7f03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import dotenv\n",
    "dotenv.load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "9e6b0eb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = NvidiaLLMClient(config={'api_key': os.getenv('NVIDIA_API_KEY'),'model_name': 'qwen/qwen2.5-7b-instruct'})\n",
    "reranker = NvidiaRerankerClient(config={'api_key': os.getenv('NVIDIA_API_KEY'),'model_name': \"nv-rerank-qa-mistral-4b:1\"})\n",
    "# reranker = HFRerankerClient()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "114ce917",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydantic import BaseModel, Field, constr, condecimal\n",
    "\n",
    "class ProductModel(BaseModel):\n",
    "    productTitle: constr(min_length=1, max_length=200) = Field(\n",
    "        ...,\n",
    "        title=\"Product Title\",\n",
    "        description=\"The full title of the product\"\n",
    "    )\n",
    "    price: condecimal(gt=0, decimal_places=2) = Field(\n",
    "        ...,\n",
    "        title=\"Product Price\",\n",
    "        description=\"Unit price (must be > 0, two decimal places).\"\n",
    "    )\n",
    "    manufacturer: constr(min_length=1, max_length=1000) = Field(\n",
    "        ...,\n",
    "        title=\"Manufacturer\",\n",
    "        description=\"Name of the product manufacturer.\"\n",
    "    )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "2d6c1215",
   "metadata": {},
   "outputs": [],
   "source": [
    "url = \"https://www.amazon.com/Instant-Pot-Multi-Use-Programmable-Pressure/dp/B00FLYWNYQ?_encoding=UTF8&content-id=amzn1.sym.2f889ce0-246f-467a-a086-d9a721167240&dib=eyJ2IjoiMSJ9.2EzBddTDEktLY8ckTsraM_cZ6pzKuNkA6y_gLR0-Uz1ekttQU6tuQEcjb8PThy0PfhvxLqeYWh3N7pQrGgRxAWzapVklC_aU6xBzD-3Wwqx3qyQRHsmOhPRsSpeCOIIZqS3SKDowZEPYrGnCbRMt5vxnsYMW-fD-zBbgeoeGYmbsN2U6_HNhLjrpePKCbQPmnZBJ9UhgYE4fE3DVuYm8xlJe9l5GixDLVFtZUq4m5FE.Ol-jiuu9P6mQie0yXLJj-Ht5-TXmIXuRPije85p_YVo&dib_tag=se&keywords=cooker&pd_rd_r=2cede598-f3ae-49ca-8a46-e5945a9c2631&pd_rd_w=2HLSC&pd_rd_wg=ZyUUn&qid=1749508157&sr=8-3\"\n",
    "schema = ProductModel  # pydantic class\n",
    "\n",
    "# read html file \n",
    "# with open(r'C:\\Users\\abdfa\\Desktop\\UNI STUFFING\\GRADUATION PROJECT\\Group Work\\MCP_WEB2JSON\\0000.htm', 'r', encoding='utf-8') as file:\n",
    "#     content = file.read()\n",
    "\n",
    "# with open(r'C:\\Users\\abdfa\\Desktop\\UNI STUFFING\\GRADUATION PROJECT\\Group Work\\MCP_WEB2JSON\\Amazon.com_ Instant Pot Duo 7-in-1 Electric Pressure Cooker, Slow Cooker, Rice Cooker, Steamer, Sauté, Yogurt Maker, Warmer & Sterilizer, Includes App With Over 800 Recipes, Stainless Steel, 6 Quart.htm', 'r', encoding='utf-8') as file:\n",
    "#     content = file.read()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "3bc223d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt_template = \"\"\"\n",
    "You are a helpful assistant that extracts structured data from web pages.\n",
    "You will be given a web page and you need to extract the following information:\n",
    "{content}\n",
    "\n",
    "schema: {schema}\n",
    "Please provide the extracted data in JSON format.\n",
    "WITH ONLY THE FIELDS THAT ARE IN THE SCHEMA.\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "475fccd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "classification_prompt_template = schema.model_json_schema()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "974417de",
   "metadata": {},
   "outputs": [],
   "source": [
    "# classification_prompt_template = \"\"\"\n",
    "#     # HTML Chunk Relevance Classification Prompt\n",
    "\n",
    "#     You are an HTML content classifier. Your task is to analyze an HTML chunk against a given schema and determine if the content is relevant.\n",
    "\n",
    "#     ## Instructions:\n",
    "#     1. Carefully examine the provided HTML chunk\n",
    "#     2. Compare it against the given schema/criteria\n",
    "#     3. Determine if the HTML chunk contains content that matches or is relevant to the schema\n",
    "#     4. Respond with ONLY a JSON object containing a single field \"relevant\" with value 1 (relevant) or 0 (not relevant)\n",
    "\n",
    "#     ## Input Format:\n",
    "#     **Schema/Criteria:**\n",
    "#     {schema}\n",
    "\n",
    "#     **HTML Chunk:**\n",
    "#     ```html\n",
    "#     {content}\n",
    "#     ```\n",
    "\n",
    "#     ## Output Format:\n",
    "#     Your response must be ONLY a valid JSON object with no additional text:\n",
    "\n",
    "#     ```json\n",
    "#     {{\n",
    "#     \"relevant\": 1\n",
    "#     }}\n",
    "#     ```\n",
    "\n",
    "#     OR\n",
    "\n",
    "#     ```json\n",
    "#     {{\n",
    "#     \"relevant\": 0\n",
    "#     }}\n",
    "#     ```\n",
    "\n",
    "#     ## Classification Rules:\n",
    "#     - Output 1 if the HTML chunk contains content that matches the schema criteria\n",
    "#     - Output 0 if the HTML chunk does not contain relevant content\n",
    "#     - Consider semantic meaning, not just exact keyword matches\n",
    "#     - Look at text content, attributes, structure, and context\n",
    "#     - Ignore purely structural HTML elements (like divs, spans) unless they contain relevant content\n",
    "#     - Be STRICT in your evaluation - only mark as relevant (1) if there is clear, meaningful content that directly relates to the schema\n",
    "#     - Empty elements, placeholder text, navigation menus, headers/footers, and generic UI components should typically be marked as not relevant (0)\n",
    "#     - The HTML chunk does not need to contain ALL schema information, but it must contain SUBSTANTIAL and SPECIFIC content related to the schema\n",
    "\n",
    "#     CRITICAL: Your entire response MUST be exactly one JSON object. DO NOT include any explanations, reasoning, markdown formatting, code blocks, or additional text. Output ONLY the raw JSON object.\n",
    "#     \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "58436d65",
   "metadata": {},
   "outputs": [],
   "source": [
    "pre = BasicPreprocessor(config={'keep_tags':True})\n",
    "# llm = GeminiLLMClient(config={'api_key': os.getenv('GEMINI_API_KEY'),})\n",
    "# ai = AIExtractor(llm_client=llm ,prompt_template=prompt_template)\n",
    "ai = LLMClassifierExtractor(reranker=reranker, llm_client=llm, prompt_template=prompt_template, classifier_prompt=classification_prompt_template)\n",
    "post = PostProcessor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "c4e75e63",
   "metadata": {},
   "outputs": [],
   "source": [
    "html_chunks = [\n",
    "    \"\"\"\n",
    "    <div class=\"product-card\">\n",
    "        <h2 class=\"product-title\">Wireless Noise Cancelling Headphones</h2>\n",
    "        <p class=\"product-description\">Experience immersive sound with active noise cancellation and long battery life.</p>\n",
    "        <span class=\"price\">$299.99</span>\n",
    "        <button>Add to Cart</button>\n",
    "    </div>\n",
    "    \"\"\",\n",
    "\n",
    "    \"\"\"\n",
    "    <section class=\"blog-post\">\n",
    "        <h1>Top 5 AI Tools to Try in 2025</h1>\n",
    "        <p>Artificial intelligence continues to evolve. Here are five tools you should explore in 2025:</p>\n",
    "        <ul>\n",
    "            <li>LangChain</li>\n",
    "            <li>AutoGen</li>\n",
    "            <li>OpenDevin</li>\n",
    "            <li>FastRAG</li>\n",
    "            <li>GPTScript</li>\n",
    "        </ul>\n",
    "        <footer>Published by <strong>TechToday</strong> on June 30, 2025</footer>\n",
    "    </section>\n",
    "    \"\"\",\n",
    "\n",
    "    \"\"\"\n",
    "    <section class=\"blog-post\">\n",
    "        <h1>Top 5 AI Tools to Try in 2025</h1>\n",
    "        <p>Artificial intelligence continues to evolve. Here are five tools you should explore in 2025:</p>\n",
    "        <ul>\n",
    "            <li>LangChain</li>\n",
    "            <li>AutoGen</li>\n",
    "            <li>OpenDevin</li>\n",
    "            <li>FastRAG</li>\n",
    "            <li>GPTScript</li>\n",
    "        </ul>\n",
    "        <footer>Published by <strong>TechToday</strong> on June 30, 2025</footer>\n",
    "    </section>\n",
    "    \"\"\",\n",
    "\n",
    "    \"\"\"\n",
    "    <div class=\"review\">\n",
    "        <h3>User Review: Amazing Performance!</h3>\n",
    "        <p>I’ve been using this laptop for a few months and it’s blazing fast. Great for deep learning workloads!</p>\n",
    "        <div class=\"rating\">Rating: ⭐⭐⭐⭐⭐</div>\n",
    "        <span class=\"user\">– Sarah M.</span>\n",
    "    </div>\n",
    "    \"\"\"\n",
    "]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "bb4edecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(html_chunks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "9927a78e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "raw scores [-11.34375   -13.8984375 -14.7578125 -14.7578125]\n",
      "Sigmoid scores: [1.18431390e-05 9.20417541e-07 3.89729515e-07 3.89729515e-07]\n",
      "Normalized scores: [1.        0.0463345 0.        0.       ]\n",
      "Filtered pairs:\n",
      "[(Document(metadata={'relevance_score': -11.34375}, page_content='\\n    <div class=\"product-card\">\\n        <h2 class=\"product-title\">Wireless Noise Cancelling Headphones</h2>\\n        <p class=\"product-description\">Experience immersive sound with active noise cancellation and long battery life.</p>\\n        <span class=\"price\">$299.99</span>\\n        <button>Add to Cart</button>\\n    </div>\\n    '), 1.0)]\n"
     ]
    }
   ],
   "source": [
    "output = reranker.rerank(query=classification_prompt_template,passages=html_chunks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "b77015f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "    <div class=\"product-card\">\n",
      "        <h2 class=\"product-title\">Wireless Noise Cancelling Headphones</h2>\n",
      "        <p class=\"product-description\">Experience immersive sound with active noise cancellation and long battery life.</p>\n",
      "        <span class=\"price\">$299.99</span>\n",
      "        <button>Add to Cart</button>\n",
      "    </div>\n",
      "    \n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "for o in output:\n",
    "    print(o)\n",
    "    print('-'*80)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "bb3fa1b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "c1c43f7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# ai.extract(chunks=[\"the price is $1000\", \"the title is 'NVIDIA H100 SXM'\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "9c78eec9",
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe = Pipeline(preprocessor=pre, ai_extractor=ai, postprocessor=post)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "92a5fc23",
   "metadata": {},
   "outputs": [],
   "source": [
    "config = {\n",
    "    'keep_tags': True,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "f07e1aca",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import os\n",
    "\n",
    "# content = \"\"\"<html>\n",
    "# <body>\n",
    "# \"\"\"\n",
    "\n",
    "# from web2json.ai_extractor import HFRerankerClient, LLMClassifierExtractor, NvidiaLLMClient\n",
    "\n",
    "# hf_reranker = HFRerankerClient()\n",
    "# llm_client = NvidiaLLMClient(config={\"api_key\": os.environ.get('NVIDIA_API_KEY')})\n",
    "# extractor = LLMClassifierExtractor(\n",
    "#     reranker=hf_reranker,\n",
    "#     llm_client=llm_client,\n",
    "#     prompt_template=\"Extract from: {content} using schema: {schema}\",\n",
    "#     classifier_prompt=\"What is the price?\"\n",
    "# )\n",
    "\n",
    "# # Run using HuggingFace reranker\n",
    "# result = extractor.extract(content=content, schema=schema, hf=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "79cf2321",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
      "raw scores [-12.40625   -12.453125  -12.46875   -12.5546875 -12.6875   ]\n",
      "Sigmoid scores: [4.09291105e-06 3.90548374e-06 3.84493506e-06 3.52831186e-06\n",
      " 3.08949445e-06]\n",
      "Normalized scores: [1.         0.81321087 0.75286836 0.43732325 0.        ]\n",
      "Filtered pairs:\n",
      "[(Document(metadata={'relevance_score': -12.40625}, page_content='<html><body><div><div><div><div><div><div>\\n<div> <h1> About this item </h1> <ul> <li><span> 7-IN-1 FUNCTIONALITY: Pressure cook, slow cook, rice cooker, yogurt maker, steamer, sauté pan and food warmer.  </span></li> <li><span> QUICK ONE-TOUCH COOKING: 13 customizable Smart Programs for pressure cooking ribs, soups, beans, rice, poultry, yogurt, desserts and more.  </span></li> <li><span> COOK FAST OR SLOW: Pressure cook delicious one-pot meals up to 70% faster than traditional cooking methods or slow cook your favorite traditional recipes – just like grandma used to make.  </span></li> <li><span> QUICK AND EASY CLEAN UP: Finger-print resistant, stainless-steel sides and dishwasher-safe lid, inner pot, and accessories.  </span></li> <li><span> SAFETY FEATURES: Includes over 10 safety features, plus overheat protection and safe-locking lid  </span></li> <li><span> GREAT FOR GROWING FAMILIES: Cook for up to 6 people – perfect for growing families, or meal prepping and batch cooking for singles.  </span></li> <li><span> VERSATILE INNER COOKING POT: We use food-grade stainless-steel, a tri-ply bottom for more even cooking and perfect for sautéing  </span></li> <li><span> DISCOVER AMAZING RECIPES: Includes the free Instant Brands Connect App, where you can find new recipes to create quick favorites and prepare delicious meals, available for iOS and Android.  </span></li> </ul>\\n<div> <span>›</span>  See more product details  </div> <div><div> \\xa0 Report an issue with this product or seller</div></div><h4>There is a newer model of this item:</h4><div><div> <div> Instant Pot RIO, 7-in-1 Electric Multi-Cooker, PressureCooker, SlowCooker, RiceCooker, Steamer, Sauté, Yogurt Maker, &amp; Warmer, Includes App With Over 800 Recipes, 6 Quart  <span>$94.95</span>    (2,377)  <span>In Stock</span> </div> </div></div><div><div><h4>Product voltage: 120</h4><div> <span> <p><span>This product is compatible with outlets that support 120 volts and might require a converter when used outside of the United States.</span></p> </span> </div></div></div><div><div><div>\\n<span> <span><span><input/><span> <span>More filters</span> </span></span></span> </span> </div></div></div><div><div><div><div><div><div><div><div><div> <h4>\\n Price  \\n </h4>\\n<div> <div> <span>\\n<span> <span><span><input/><span> <span>&lt;$25</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span> <span>$25 - $50</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span> <span>$50 - $100</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span> <span>$100 - $200</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span> <span>&gt;$200</span> </span></span></span> </span> </span>\\n</div> </div> </div></div></div></div></div></div></div></div></div></div> </div><h2>\\n            Discover similar items</h2></div></div></div></div></div></body></html>'), 1.0), (Document(metadata={'relevance_score': -12.453125}, page_content='<html><body><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div> <h4>\\n Color  \\n \\n Capacity  \\n \\n Grade  \\n \\n Power  \\n \\n Heat Source  \\n \\n Material  \\n \\n Slow Cooker Type  \\n \\n Brand  \\n \\n Closure  \\n \\n Width  \\n \\n Finish  \\n \\n Control Type  \\n \\n Free From  \\n \\n Heating Elements  \\n \\n Heating Type  \\n \\n Depth  \\n \\n Premium Brands  \\n \\n Output Wattage  \\n \\n Features  \\n \\n Uses  \\n \\n Inclusions  \\n \\n Height  \\n \\n Length  \\n \\n Lid Material  \\n \\n Shape  \\n \\n Top Brands in Home &amp; Kitchen  \\n \\n Style  \\n </h4>\\n<div> <div> <span>\\n<span> <span><span><input/><span>\\n<span>Black</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Grey</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>White</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Brown</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Beige</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Red</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Pink</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Orange</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Yellow</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Ivory</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Green</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Blue</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Purple</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Gold</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Silver</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Multi</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><input/><span>\\n<span>Clear</span> </span></span></span> </span> </span>\\n<span>\\n<span> <span><span><span>\\n<span>Stainless Steel</span> </span></span></span> </span> </span>\\n</div> </div> <span> <button>\\n<span>Clear Filters</span> </button>\\n</span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></body></html>'), 0.8132108732268714), (Document(metadata={'relevance_score': -12.46875}, page_content=\"<html><body><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><form><div><div><div>\\n<input/>\\n<input/>\\n<input/>\\n<div> <div> <span>$</span><span><span><span>$79.99</span><span><span>79<span>.</span></span><span>99</span></span></span></span> <span> \\n                    ()\\n            </span> <span> Includes selected options. </span> <span> Includes initial monthly payment and selected options. </span> <span> <span> <span>\\n Details  </span>\\n</span> <div> <div> <div> <div> <div><div> <div> <span>Price</span> <span> <span> <span> (</span><span>$</span><span>79<span>.</span></span><span>99</span><span>x)</span> </span> </span> </div> <div> <span> <span> <span>$</span><span>79<span>.</span></span><span>99</span> </span> </span> </div> </div></div> </div> <div> <div><div> <div> <span>Subtotal</span> </div> <div> <span> <span>$</span><span><span><span>$79.99</span><span><span>79<span>.</span></span><span>99</span></span></span></span> </span> </div> </div></div> <div><div> <div> <span>Subtotal</span> </div> </div></div> <div> <div> <span>Initial payment breakdown</span> </div> </div> <div> <span>Shipping cost, delivery date, and order total (including tax) shown at checkout.</span>\\n</div> </div> </div> </div> </div> </span> </div> </div> <div> <span> <span><span><input/><span>Add to Cart</span></span></span> </span> </div><div> <div> <span><span><input/><span> Buy Now </span></span></span> </div> </div><div> <div><div><div> <span> Enhancements you chose aren't available for this seller. </span> <span>  Details  </span> <div> <div> <div> <div> <span> To add the following enhancements to your purchase, choose a different seller. </span> </div> <div> <span>%cardName%</span> </div> </div> </div> </div> </div></div></div> <div><div><div> <span> ${cardName} not available for the seller you chose </span> </div></div></div> <div><div><div> <span> ${cardName} unavailable for quantities greater than ${maxQuantity}. </span> </div></div></div> </div></div></div></div></form></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></body></html>\"), 0.7528683592125947)]\n",
      "prompt:  \n",
      "You are a helpful assistant that extracts structured data from web pages.\n",
      "You will be given a web page and you need to extract the following information:\n",
      "<html><body><div><div><div><div><div><div>\n",
      "<div> <h1> About this item </h1> <ul> <li><span> 7-IN-1 FUNCTIONALITY: Pressure cook, slow cook, rice cooker, yogurt maker, steamer, sauté pan and food warmer.  </span></li> <li><span> QUICK ONE-TOUCH COOKING: 13 customizable Smart Programs for pressure cooking ribs, soups, beans, rice, poultry, yogurt, desserts and more.  </span></li> <li><span> COOK FAST OR SLOW: Pressure cook delicious one-pot meals up to 70% faster than traditional cooking methods or slow cook your favorite traditional recipes – just like grandma used to make.  </span></li> <li><span> QUICK AND EASY CLEAN UP: Finger-print resistant, stainless-steel sides and dishwasher-safe lid, inner pot, and accessories.  </span></li> <li><span> SAFETY FEATURES: Includes over 10 safety features, plus overheat protection and safe-locking lid  </span></li> <li><span> GREAT FOR GROWING FAMILIES: Cook for up to 6 people – perfect for growing families, or meal prepping and batch cooking for singles.  </span></li> <li><span> VERSATILE INNER COOKING POT: We use food-grade stainless-steel, a tri-ply bottom for more even cooking and perfect for sautéing  </span></li> <li><span> DISCOVER AMAZING RECIPES: Includes the free Instant Brands Connect App, where you can find new recipes to create quick favorites and prepare delicious meals, available for iOS and Android.  </span></li> </ul>\n",
      "<div> <span>›</span>  See more product details  </div> <div><div>   Report an issue with this product or seller</div></div><h4>There is a newer model of this item:</h4><div><div> <div> Instant Pot RIO, 7-in-1 Electric Multi-Cooker, PressureCooker, SlowCooker, RiceCooker, Steamer, Sauté, Yogurt Maker, &amp; Warmer, Includes App With Over 800 Recipes, 6 Quart  <span>$94.95</span>    (2,377)  <span>In Stock</span> </div> </div></div><div><div><h4>Product voltage: 120</h4><div> <span> <p><span>This product is compatible with outlets that support 120 volts and might require a converter when used outside of the United States.</span></p> </span> </div></div></div><div><div><div>\n",
      "<span> <span><span><input/><span> <span>More filters</span> </span></span></span> </span> </div></div></div><div><div><div><div><div><div><div><div><div> <h4>\n",
      " Price  \n",
      " </h4>\n",
      "<div> <div> <span>\n",
      "<span> <span><span><input/><span> <span>&lt;$25</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span> <span>$25 - $50</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span> <span>$50 - $100</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span> <span>$100 - $200</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span> <span>&gt;$200</span> </span></span></span> </span> </span>\n",
      "</div> </div> </div></div></div></div></div></div></div></div></div></div> </div><h2>\n",
      "            Discover similar items</h2></div></div></div></div></div></body></html>\n",
      "\n",
      "<html><body><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div> <h4>\n",
      " Color  \n",
      " \n",
      " Capacity  \n",
      " \n",
      " Grade  \n",
      " \n",
      " Power  \n",
      " \n",
      " Heat Source  \n",
      " \n",
      " Material  \n",
      " \n",
      " Slow Cooker Type  \n",
      " \n",
      " Brand  \n",
      " \n",
      " Closure  \n",
      " \n",
      " Width  \n",
      " \n",
      " Finish  \n",
      " \n",
      " Control Type  \n",
      " \n",
      " Free From  \n",
      " \n",
      " Heating Elements  \n",
      " \n",
      " Heating Type  \n",
      " \n",
      " Depth  \n",
      " \n",
      " Premium Brands  \n",
      " \n",
      " Output Wattage  \n",
      " \n",
      " Features  \n",
      " \n",
      " Uses  \n",
      " \n",
      " Inclusions  \n",
      " \n",
      " Height  \n",
      " \n",
      " Length  \n",
      " \n",
      " Lid Material  \n",
      " \n",
      " Shape  \n",
      " \n",
      " Top Brands in Home &amp; Kitchen  \n",
      " \n",
      " Style  \n",
      " </h4>\n",
      "<div> <div> <span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Black</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Grey</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>White</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Brown</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Beige</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Red</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Pink</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Orange</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Yellow</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Ivory</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Green</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Blue</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Purple</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Gold</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Silver</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Multi</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><input/><span>\n",
      "<span>Clear</span> </span></span></span> </span> </span>\n",
      "<span>\n",
      "<span> <span><span><span>\n",
      "<span>Stainless Steel</span> </span></span></span> </span> </span>\n",
      "</div> </div> <span> <button>\n",
      "<span>Clear Filters</span> </button>\n",
      "</span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></body></html>\n",
      "\n",
      "<html><body><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><form><div><div><div>\n",
      "<input/>\n",
      "<input/>\n",
      "<input/>\n",
      "<div> <div> <span>$</span><span><span><span>$79.99</span><span><span>79<span>.</span></span><span>99</span></span></span></span> <span> \n",
      "                    ()\n",
      "            </span> <span> Includes selected options. </span> <span> Includes initial monthly payment and selected options. </span> <span> <span> <span>\n",
      " Details  </span>\n",
      "</span> <div> <div> <div> <div> <div><div> <div> <span>Price</span> <span> <span> <span> (</span><span>$</span><span>79<span>.</span></span><span>99</span><span>x)</span> </span> </span> </div> <div> <span> <span> <span>$</span><span>79<span>.</span></span><span>99</span> </span> </span> </div> </div></div> </div> <div> <div><div> <div> <span>Subtotal</span> </div> <div> <span> <span>$</span><span><span><span>$79.99</span><span><span>79<span>.</span></span><span>99</span></span></span></span> </span> </div> </div></div> <div><div> <div> <span>Subtotal</span> </div> </div></div> <div> <div> <span>Initial payment breakdown</span> </div> </div> <div> <span>Shipping cost, delivery date, and order total (including tax) shown at checkout.</span>\n",
      "</div> </div> </div> </div> </div> </span> </div> </div> <div> <span> <span><span><input/><span>Add to Cart</span></span></span> </span> </div><div> <div> <span><span><input/><span> Buy Now </span></span></span> </div> </div><div> <div><div><div> <span> Enhancements you chose aren't available for this seller. </span> <span>  Details  </span> <div> <div> <div> <div> <span> To add the following enhancements to your purchase, choose a different seller. </span> </div> <div> <span>%cardName%</span> </div> </div> </div> </div> </div></div></div> <div><div><div> <span> ${cardName} not available for the seller you chose </span> </div></div></div> <div><div><div> <span> ${cardName} unavailable for quantities greater than ${maxQuantity}. </span> </div></div></div> </div></div></div></div></form></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></body></html>\n",
      "\n",
      "schema: {'properties': {'productTitle': {'description': 'The full title of the product', 'maxLength': 200, 'minLength': 1, 'title': 'Product Title', 'type': 'string'}, 'price': {'anyOf': [{'exclusiveMinimum': 0.0, 'type': 'number'}, {'type': 'string'}], 'description': 'Unit price (must be > 0, two decimal places).', 'title': 'Product Price'}, 'manufacturer': {'description': 'Name of the product manufacturer.', 'maxLength': 1000, 'minLength': 1, 'title': 'Manufacturer', 'type': 'string'}}, 'required': ['productTitle', 'price', 'manufacturer'], 'title': 'ProductModel', 'type': 'object'}\n",
      "Please provide the extracted data in JSON format.\n",
      "WITH ONLY THE FIELDS THAT ARE IN THE SCHEMA.\n",
      "\n",
      "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
      "Final output: {'productTitle': 'Instant Pot RIO, 7-in-1 Electric Multi-Cooker, PressureCooker, SlowCooker, RiceCooker, Steamer, Sauté, Yogurt Maker, & Warmer, Includes App With Over 800 Recipes, 6 Quart', 'price': 94.95, 'manufacturer': 'Instant Pot'}\n",
      "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'productTitle': 'Instant Pot RIO, 7-in-1 Electric Multi-Cooker, PressureCooker, SlowCooker, RiceCooker, Steamer, Sauté, Yogurt Maker, & Warmer, Includes App With Over 800 Recipes, 6 Quart',\n",
       " 'price': 94.95,\n",
       " 'manufacturer': 'Instant Pot'}"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipe.run(content=url,is_url=True, schema=schema, hf=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c4109c9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef3a300c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}