import streamlit as st import pandas as pd from langchain_core.documents import Document from langchain.prompts import PromptTemplate from langchain_huggingface import HuggingFaceEndpoint import json from dotenv import load_env load_env() # --- Streamlit Page Configuration --- st.set_page_config( page_title="URS Document Extractor", page_icon="📄", layout="wide" ) st.title("📄 URS Document Data Extractor (API Version)") st.markdown("This app extracts key information from a URS document using the fast and reliable Hugging Face Inference API.") # --- Core Logic --- # Using the hardcoded context you provided CONTEXT_DOCUMENTS = [ Document(id='2345ac4a-b3ee-4444-bc09-3a8ebceaaa3e', metadata={}, page_content='||Revision History|4|\n|1.0|PROJECT DESCRIPTION|5|\n|2.0|PROCESS DESCRIPTION|5|\n|2.1|Name of the Equipment / System / Facility|5|\n|2.2|Purpose of the Equipment / System / Facility|5|\n|2.3|Number of Equipments Required|5|\n|2.4|Process Description and Schematic Flow diagram|5|'), Document(id='38fdcc4a-40f4-4f56-bc5c-c8eac5aa42a7', metadata={}, page_content='|3.5|Desirable material unloading method from the equipment / System|Desirable material unloading method from the equipment / System|Desirable material unloading method from the equipment / System|'), Document(id='5f7e1af4-114a-4b97-9da9-cfcf258541f4', metadata={}, page_content='|---|---|\n|2.0|PROCESS DESCRIPTION|\n|2.1|Name of the Equipment|\n||Pure Steam Generation and Distribution System.|\n|2.2|Purpose of the Equipment|\n||To provide Pure Steam as per pharmacopeia’s specifications.|\n|2.3|Number of Equipments Required|\n||Two Equipment’s|'), Document(id='7f4dffbe-f6f3-42ed-bc3c-821063de39bc', metadata={}, page_content='|5|Compound gauge|Warre / Baumer|\n|6|ORP Sensor|Georg fischer|\n|7|Manual ball valve for jacket condensate|Shaktti /approved vendor|\n|8|PLC|Allen bradlly / Siemens|\n|9|Temperature sensor|Radix|\n|10|Level transmitter|Endress + Hauses|\n|11|Pump|Ground foss|\n|12|Safety valve|Approved vendor|'), Document(id='f12dd67d-592b-4059-9e09-91f15c5817c0', metadata={}, page_content='|3.3|Desired outcome from the Equipment|6|\n|3.4|Desirable material loading method into the equipment / System|6|\n|3.5|Desirable material unloading method from the Equipment / System|6|\n|3.6|Expected operational hours per day and output in lots per day|6|\n|3.7|Preferable method of cleaning|6|'), Document(id='e879abf7-7202-49a1-9ac3-c2316872d84b', metadata={}, page_content='agents, etc.)
2. Preventive maintenance manual including:
• Equipment and Instrument list with component descriptions
• Electrical component parts list with descriptions
• Spare parts list with appropriate identification nos., if any
• Change parts list with appropriate'), Document(id='12716da2-cd79-4fae-b9b8-beb8406cfc29', metadata={}, page_content='|3.9|Utility Name|Specification|Purpose|\n|3.9|Compressed Air|Pharma grade, oil free.
Pressure: NLT 6.0 kg / cm2|For pneumatic operations|\n|3.9|Electric supply|400-440 V, 50 Hz, 3 phase|Power supply|\n|3.9|Purified water|2 Kg/Cm2|For product input|'), Document(id='737b9974-8fa7-4e7e-888b-8df3b04156a1', metadata={}, page_content='|9.0|Operational Qualification|YES|Supplier / user|\n|9.0|Performance Qualification|YES|Supplier / user|\n|10.0|ABBREVIATIONS|ABBREVIATIONS|ABBREVIATIONS| \nPage **12** of **13** \n__________________________________________________________________________________'), Document(id='94467a07-391a-48ac-a389-49daecba4ebb', metadata={}, page_content='if any
• Change parts list with appropriate identification nos., if any
• The equipment shall be designed to use standard tools for maintenance and repairing.
• Any special tools required for maintenance should be provided along with the
equipment.
3. Drawings:
• Engineering'), Document(id='d3016427-a1c3-414a-b378-7c9847670ce0', metadata={}, page_content='|3.4|Desirable material loading method into the equipment / System|Desirable material loading method into the equipment / System|Desirable material loading method into the equipment / System|'), Document(id='506745d1-33d9-4f81-bf81-235e7a86f11d', metadata={}, page_content='|3.1|Production Stage|Production Stage|Production Stage|\n||Generation of pure steam.|Generation of pure steam.|Generation of pure steam.|\n|3.2|Material inputs to the equipment and function|Material inputs to the equipment and function|Material inputs to the equipment and function|'), Document(id='8de5e683-6ed2-4514-b8f4-9ef14886636c', metadata={}, page_content='on post installation vendor equipment and training for Operation and
Maintenance to staff concerned.|'), Document(id='ce978272-570a-4c59-8bb7-3addff00cea3', metadata={}, page_content='**END OF DOCUMNET** \nPage **13** of **13** \n__________________________________________________________________________________'), Document(id='03a50379-c0d3-45e7-b99d-f6cf4b0c80f4', metadata={}, page_content='**USER REQUIREMENT SPECIFICATION FOR PURE**\n**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|S.No.|Name of the Content|Page No.|\n|---|---|---|\n||Table of Contents|2 & 3|\n||Revision History|4|\n|1.0|PROJECT DESCRIPTION|5|'), Document(id='61ecc642-7bad-499d-84bb-2daa85c687ac', metadata={}, page_content='|Name / Designation|Signature|Date|\n|---|---|---|\n|Prepared By|Prepared By|Prepared By|\n||||\n|Reviewed By|Reviewed By|Reviewed By|\n||||\n|Approved By|Approved By|Approved By|\n|||| \n**END OF DOCUMNET** \nPage **13** of **13**'), Document(id='2bd9594d-54de-42fd-ae9e-86b5a108589f', metadata={}, page_content='|3.19|Any other specific requirements|9 - 10|\n|4.0|GMP REQUIREMENTS|10|\n|4.1|Main component|10| \nPage **2** of **13** \n__________________________________________________________________________________ \n**USER REQUIREMENT SPECIFICATION FOR PURE**\n**TITLE** **:**'), Document(id='ec3f77f5-e3e2-4fee-9f7b-7d66c5be9524', metadata={}, page_content='|---|---|\n|Department / Area|Production|\n|Quantity Required|02 No’s.| \n|S.No.|Name of the Content|Page No.|\n|---|---|---|\n||Cover Page|1| \nPage **1** of **13** \n__________________________________________________________________________________ \n**USER REQUIREMENT SPECIFICATION FOR PURE**'), Document(id='8f9ced91-f33e-478f-b97e-cdf9a73a97fb', metadata={}, page_content='**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|S.No.|Name of the Content|Page No.|\n|---|---|---|\n|4.2|Specification for Material of Construction|10|\n|4.3|Working area Environmental requirement|10|'), Document(id='af6b7e87-0e23-43d8-b0d2-8c3d79bda7a3', metadata={}, page_content='00 **––** First Issue \n|1.0|PROJECT DESCRIPTION|\n|---|---|'), Document(id='baac7140-1017-4d04-8ffd-93341d03ae29', metadata={}, page_content='unit.|In feed through SS 316, < 0.8 Ra electro polished pipeline from Purified Water storage tank to
Pure steam generation unit.|'), Document(id='27b03f2d-2b87-4163-8695-152037dcd7ca', metadata={}, page_content='acceptance certificates (such as weld inspection, Passivation,
pressure / vacuum holds, etc.)
5. Validation documents:
• Detailed list of modifications after contract &/or in final approved design
• Material specifications and test certificates
• Instrument Calibration'), Document(id='a654d68f-5f43-4c4e-993a-e857a568c6dd', metadata={}, page_content='help Pharma Ltd to prepare the SOP of Operation, Cleaning and
Preventive maintenance of the equipment.|FAT required before delivery. Supplier should provide a checklist and is responsible for total
completion up to performance qualification including training.
i. Technical staff of'), Document(id='d438426d-95a0-4fdb-afc3-320df8d8f915', metadata={}, page_content='ORP Sensor Georg fischer
7 Manual ball valve for jacket condensate Shaktti /approved vendor
8 PLC Allen bradlly / Siemens
9 Temperature sensor Radix
10 Level transmitter Endress + Hauses
11 Pump Ground foss
12 Safety valve Approved vendor|'), Document(id='17c60f16-b9ae-4661-8507-18bb50751992', metadata={}, page_content='**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|4.1|Main component|Col3|\n|---|---|---|\n|4.1|Main component should comply with valid regulated guidelines for cGMP practice.|Main component should comply with valid regulated guidelines for cGMP practice.|'), Document(id='74431d53-260f-48ac-9886-4665602ef9c0', metadata={}, page_content='ORP Sensor Georg fischer
7 Manual ball valve for jacket condensate Shaktti /approved vendor
8 PLC Allen bradlly / Siemens
9 Temperature sensor Radix
10 Level transmitter Endress + Hauses
11 Pump Ground foss
12 Safety valve Approved vendor|• All product contact pipeline should be'), Document(id='326a9661-293d-4997-8e39-e833e21828cb', metadata={}, page_content='shall be present up to
first three successful performance qualifications run.
ii. Technical staff of supplier shall train the applicable equipment operator of Pharma Ltd
before operation qualification testing.
iii. Technical staff shall help Pharma Ltd to prepare the SOP of Operation,'), Document(id='e29901d5-7e7e-49a5-b2ef-073cca9cee15', metadata={}, page_content='operator of Pharma Ltd
before operation qualification testing.
iii. Technical staff shall help Pharma Ltd to prepare the SOP of Operation, Cleaning and
Preventive maintenance of the equipment.|FAT required before delivery. Supplier should provide a checklist and is responsible for'), Document(id='3d335625-329b-48da-ae86-7139fd2fdf43', metadata={}, page_content='**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|Col1|regulator
• Required indication of any respective fault at the P & I diagram with LED indication|\n|---|---|\n|3.11|Desired level of instrumentation and Accuracy levels|'), Document(id='dcea4482-c32e-4d63-b93c-e573b2006aab', metadata={}, page_content='**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001**'), Document(id='b0afae6c-c048-4987-b2c2-b5e9545dcba4', metadata={}, page_content='|3.9|Required Utilities: The system will interface with required utilities such as compressed air,
electric supply, purified water and plant steam.|Required Utilities: The system will interface with required utilities such as compressed air,
electric supply, purified water and plant'), Document(id='88210785-aedf-49ba-a68b-6dc2296fea1a', metadata={}, page_content='|3.9|Purified water|2 Kg/Cm2|For product input|\n|3.9|Plant steam supply|6.0 kg / cm2|For Column Heating|\n|3.9|Vendor should specify the utility requirements|Vendor should specify the utility requirements|Vendor should specify the utility requirements|'), Document(id='59ccbc56-557f-4978-a3a9-c31b62317161', metadata={}, page_content='air,
electric supply, purified water and plant steam.|Required Utilities: The system will interface with required utilities such as compressed air,
electric supply, purified water and plant steam.|'), Document(id='b2d87404-8c6e-4217-a3d4-c99adc2fd6f5', metadata={}, page_content='|8.1|Foot prints of Machine, Utilities and Piping requirements.|Foot prints of Machine, Utilities and Piping requirements.|Foot prints of Machine, Utilities and Piping requirements.|\n|8.2|Start up support|Start up support|Start up support|'), Document(id='2ad3e821-0ef1-4189-83ea-cedee05b7e14', metadata={}, page_content='through the Supervisory Control and Data Acquisition System
(SCADA). Operation of system is through PLC, which is programmed and stored in
CPU of the PLC set.
• The equipment should have control system to stop the feed pump in case of low plant
steam temperature and low feed water level'), Document(id='b5c5c47d-ed51-46d6-a044-403a7a0ac811', metadata={}, page_content='|3.14|•
Required attachment to Purified water storage tank for input of feed water

Required attachment to pure steam distribution loop.

Required attachment to Plant steam generator and Compressed air generator|\n|3.15|Software details|'), Document(id='9311d9b1-a5ef-493b-a8b7-b9701b2bd5fe', metadata={}, page_content='is programmed and stored in
CPU of the PLC set.
• The equipment should have control system to stop the feed pump in case of low plant
steam temperature and low feed water level in column.
• The equipment should have pressure control system to regulate the cooling water
• The'), Document(id='d095f3c6-4c15-4d8a-8578-0bf6d6b9e516', metadata={}, page_content='|4.3|Working area Environmental requirement|10|\n|4.4|Desired means for avoiding contamination & cross contamination of the
products|10|\n|4.5|Power supply – Specify if uninterrupted power supply is required or not|10|'), Document(id='d45c1cf6-ad81-4406-97b9-7b7b6a8e39e5', metadata={}, page_content='PLC set.
• The equipment should have control system to stop the feed pump in case of low plant
steam temperature and low feed water level in column.
• The equipment should have pressure control system to regulate the cooling water
• The equipment should have Flow control flow meter for'), Document(id='33cdaf61-1478-4af7-a81f-abd9dc24b84f', metadata={}, page_content='|3.18|Least Count (if applicable)|Least Count (if applicable)|\n|3.18|Minimum legibility.|Minimum legibility.|\n|3.19|Any other specific requirements (e.g. Maintenance requirement)|Any other specific requirements (e.g. Maintenance requirement)|'), Document(id='55ac2b3d-d67e-419b-9f5f-799374d567ae', metadata={}, page_content='|4.0|GMP REQUIREMENTS|GMP REQUIREMENTS| \n|S. No|COMPONENT DESCRIPTION|MAKE|\n|---|---|---|\n|I|Diaphragm valves with SS handle with PTFE
diaphragm|Gemu|\n|2|Conductivity sensor|Rose mount|\n|3|Flow meter|E + H|\n|4|Pressure gauge|Warre / Baumer|\n|5|Compound gauge|Warre / Baumer|'), Document(id='86a4b33e-5951-4280-9c56-b95554954a80', metadata={}, page_content='|8.4|Any other specific requirement|Any other specific requirement|Any other specific requirement|'), Document(id='c93eef70-5136-49be-b130-b514c33d2cd1', metadata={}, page_content='|4.6|Power failure and recovery – Specify the action taken in case of power
failure.|10|\n|4.7|Any other specific GMP requirement|10 - 11|\n|5.0|SAFETY REQUIREMENTS|11|\n|5.1|Desired Product / Process safety systems|11|\n|5.2|Desired personnel safety systems|11|\n|6.0|DOCUMENTATION REQUIREMENT|11-12|'), Document(id='a5d42321-4543-4e23-b36c-e7db58755cf7', metadata={}, page_content='|9.0|VALIDATION REQUIREMENT WITH SCOPE|VALIDATION REQUIREMENT WITH SCOPE|VALIDATION REQUIREMENT WITH SCOPE|\n|9.0|Validation topic|Yes/ No|Scope|\n|9.0|Design Qualification|YES|Supplier|\n|9.0|FAT & SAT|YES|Supplier / user|\n|9.0|Installation Qualification|YES|Supplier / user|'), Document(id='5575ea25-9133-407f-936a-77687d42007f', metadata={}, page_content='**USER REQUIREMENT SPECIFICATION FOR PURE**\n**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|Name of The
Equipment / System|Pure Steam Generation and Distribution System|\n|---|---|\n|Department / Area|Production|'), Document(id='62319524-7caf-44ae-93a9-10200e24814e', metadata={}, page_content='out components make:
S. No COMPONENT DESCRIPTION MAKE
Diaphragm valves with SS handle with PTFE
I Gemu
diaphragm
2 Conductivity sensor Rose mount
3 Flow meter E + H
4 Pressure gauge Warre / Baumer
5 Compound gauge Warre / Baumer
6 ORP Sensor Georg fischer
7 Manual ball'), Document(id='05447a5d-8468-41c8-88f3-b540524ec6e5', metadata={}, page_content='|8.2|FAT required before delivery. Supplier should provide a checklist and is responsible for total
completion up to performance qualification including training.
i. Technical staff of supplier shall come to install the equipment and shall be present up to
first three successful'), Document(id='7316a81b-a1d1-46d4-9673-6155f703742f', metadata={}, page_content='|4.2|Non contact parts|SS 304|\n|4.3|Working area environmental requirement|Working area environmental requirement|\n|4.3|Machine should operate under clean environment / unclassified area.|Machine should operate under clean environment / unclassified area.|'), Document(id='7c991ef9-ab9b-47f8-a614-1c3727d04ed7', metadata={}, page_content='|12|Safety valve|Approved vendor| \nPage **9** of **13** \n__________________________________________________________________________________ \n**USER REQUIREMENT SPECIFICATION FOR PURE**\n**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001**'), Document(id='50671880-aed3-45df-9db5-6002ba29f0d6', metadata={}, page_content='|4.2|Specification for material of construction|Specification for material of construction|\n|4.2|Product contact parts|SS 316L, <0.38 µ Ra electro polished. System should be mechanically
polished and passivated and or electropolished.|\n|4.2|Non contact parts|SS 304|'), Document(id='47aa3e0a-a26d-4da0-8b6f-4522fa443c50', metadata={}, page_content='|2.5|Chemical / Physical characteristics of the process material|5|\n|2.6|Suggested capacity|5|\n|2.7|Any other specific requirement|5 - 6|\n|3.0|OPERATIONAL / FUNCTIONAL REQUIREMENTS|6|\n|3.1|Production Stage|6|\n|3.2|Material inputs to the Equipment and Function|6|'), Document(id='f83dcd01-29f5-49a8-9f05-70aa2f4cde44', metadata={}, page_content='Drawings:
• Engineering drawings (For approval, Approved, As built, As installed)
• Electrical circuit diagrams
• Piping and Instrument drawings for the product path shall meet the ASME and 3A
specifications requirements as applicable.
• System schematics.
4. Factory Acceptance'), Document(id='ba557316-f5a4-400c-b02b-defa1b21a966', metadata={}, page_content='|8.4|Any other specific requirements.|13|\n|9.0|VALIDATION REQUIREMENT WITH SCOPE|13|\n|10.0|ABBREVIATIONS|13|\n|11.0|DISCUSSION REVIEW / COMMENTS|13|\n||APPROVAL SIGNATORIES|14| \n**REVISION HISTORY** \n**Revision No.** **Date** **Revision Summary** \nPage **3** of **13**'), Document(id='c44dc000-983c-4cc3-b37b-2d2fbcd5cc6b', metadata={}, page_content='System schematics.
4. Factory Acceptance test:
• Detailed list of modifications after contract and / or in final approved design,
Material specifications and test certificates, Instrument Calibration certificates,
Functional / Factory acceptance certificates (such as weld inspection,'), Document(id='3a25bd42-6c83-4e76-a524-bf88780fed98', metadata={}, page_content='|3.12|Language requirement (Specify such as English/others).|\n|3.12|English|\n|3.13|Data Acquisition|\n|3.13|The vendor should provide the print out facility with memory and with 3 level password
protection.|\n|3.14|Attachment / connectivity with other equipments|'), Document(id='419fc230-e716-472a-b4c7-bdd5ce4794ea', metadata={}, page_content='Page **10** of **13** \n__________________________________________________________________________________ \n**USER REQUIREMENT SPECIFICATION FOR PURE**\n**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|5.2|Desired personnel safety systems|'), Document(id='227cc26c-3341-4e4f-b408-7145144c8f27', metadata={}, page_content='|3.12|Language requirement|9|\n|3.13|Data Acquisition|9|\n|3.14|Attachment / connectivity with other equipments|9|\n|3.15|Software details|9|\n|3.16|Operational Range (Minimum & Maximum)|9|\n|3.17|Tolerance Limits|9|\n|3.18|Least Count (if applicable)|9|\n|3.19|Any other specific requirements|9 - 10|'), Document(id='69cee82e-9141-49d5-982b-669746119794', metadata={}, page_content='is low, in case of insufficient evaporation, feed water pressure low.

Inner and Outer column shell should be < 0.6 Ra, electro polished. Pipeline should be
orbital welded wherever technically possible.

Required to control the water droplets, particulate matter and Endotoxin from'), Document(id='e18c71c6-d09b-472f-a2e3-c3e186e3c1a9', metadata={}, page_content='|2.5|Chemical / Physical characteristics of the process material|'), Document(id='dc7a77ff-376e-4575-ac83-5c48b0bffaf5', metadata={}, page_content='||•
Require sanitary construction features such as double tube sheets, sloped piping and low
point drains, minimum dead legs and sanitary connections.

Required uniform wetting and heat transfer. Elimination of bio growth Feed water level
control: Need PID control loop senses the'), Document(id='e5ada173-60c6-4475-b02e-0f9307af4670', metadata={}, page_content='Page **11** of **13** \n__________________________________________________________________________________ \n**USER REQUIREMENT SPECIFICATION FOR PURE**\n**TITLE** **:**\n**STEAM GENERATION AND DISTRIBUTION SYSTEM** \n**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|7.0|AUTOMATION|Col3|Col4|'), Document(id='135281c2-d96a-4e25-ae8d-90a81955a7bb', metadata={}, page_content='**REFERENCE SOP** **:** **FU4-QA-GEN-001** \n|Col1|•
Required a provision for non-condensable gas removal arrangement.|Col3|Col4|\n|---|---|---|---|\n|3.0|OPERATIONAL / FUNCTIONAL REQUIREMENTS|OPERATIONAL / FUNCTIONAL REQUIREMENTS|OPERATIONAL / FUNCTIONAL REQUIREMENTS|'), Document(id='a43c5b45-ab19-42dc-ba91-2b17ffe4ac94', metadata={}, page_content='|3.19|• All product contact pipeline should be orbital welded.
• The vendor must be able to provide routine repairs when needed beyond the warranty
period at cost to the customer.
• Required audio / visual alarms for all critical insufficiency.
Bought out components make:
S. No'), Document(id='51a793f4-0ca8-41e1-9782-0f5f03eb8133', metadata={}, page_content='vendor|• All product contact pipeline should be orbital welded.
• The vendor must be able to provide routine repairs when needed beyond the warranty
period at cost to the customer.
• Required audio / visual alarms for all critical insufficiency.
Bought out components make:
S. No'), Document(id='169e4b66-dacc-404d-b12a-a208d2a94c6d', metadata={}, page_content='|---|---|---|\n|3.16|Operational Range|Operational Range|\n|3.16|Minimum|Maximum|\n|3.16|Supplier should provide operating ranges.|Supplier should provide operating ranges.|\n|3.17|Tolerance Limits|Tolerance Limits|\n|3.17|0.2 to 0.3 of any instrument|0.2 to 0.3 of any instrument|'), Document(id='6d995642-8167-401a-983e-159aba636da1', metadata={}, page_content='and test certificates
• Instrument Calibration certificates
• Design Qualification Protocol.
• Installation Qualification Protocol
• Operational Qualification Protocol
• Required PLC validation
• Certificates of Materials and gauges with respect to NIST/NPL.
• Certificates of'), Document(id='5ff3d789-6fbd-41d7-af42-bb3cbcb8ee5b', metadata={}, page_content='should provide a checklist and is responsible for total
completion up to performance qualification including training.
i. Technical staff of supplier shall come to install the equipment and shall be present up to
first three successful performance qualifications run.
ii. Technical staff'), Document(id='0204e75a-0444-4f0f-9ada-44c95dd44d5b', metadata={}, page_content='|8.4|•
Required failure modes and effective analysis document.

Operation and maintenance manuals.

Calibration certificates with traceability|•
Required failure modes and effective analysis document.

Operation and maintenance manuals.

Calibration certificates'), Document(id='c2d6f1e7-b1e4-4916-bcc0-e1cf51d653c7', metadata={}, page_content='qualifications run.
ii. Technical staff of supplier shall train the applicable equipment operator of Pharma Ltd
before operation qualification testing.
iii. Technical staff shall help Pharma Ltd to prepare the SOP of Operation, Cleaning and
Preventive maintenance of the equipment.|')] FINAL_QUERY = { "[Equipment Name]": "What is the name of the equipment mentioned in the document?", "[URS Title]": "What is the title of the URS document as stated in the document?", "[URS #]": "Which Reference SOP is assigned to the URS?", "[Utility#]": "List the names of various utilities required to run the system (usually multiple, present as table in the input pdf)", "[URS Requirement_Utility]": "What are the required Utilities?", "[Requirement number_Utility]": "Which section number or unique requirement number corresponds to the required Utilities?", "[URS Requirement_BOM]": "What is the documentation requirement for a spare parts list?", "[Requirement number_BOM]": "Which section number corresponds to the documentation requirement for a spare parts list?", "[URS Requirement_P&ID]": "What drawings are mentioned in the documentation requirement?", "[Requirement number_P&ID]": "Which section number corresponds to the drawings mentioned in the documentation requirement?", "[URS Requirement_Surface Finish]": "What is the inner and outer column shell specification?", "[Requirement number_SF value]": "Which section number corresponds to the inner and outer column shell specification?", "[URS Requirement_GA DWG]": "What are the specifications for product contact parts?", "[Requirement number_GA DWG]": "Which section number corresponds to the specifications for product contact parts?", "[URS Requirement_MOC]": "What is the slope value of the desired level of instruments and accuracy levels?", "[Requirement number_MOC]": "Which section number corresponds to the slope value of the desired level of instruments and accuracy levels?" } # --- Function to initialize the LLM --- # This uses the Hugging Face Inference API. It's fast and reliable. @st.cache_resource def get_llm(): """Initializes the HuggingFaceEndpoint for the Llama 3 model.""" # Ensure the secret is available before initializing if "HF_TOKEN" not in st.secrets: st.error("Hugging Face token not found! Please add it to your Space secrets.", icon="🚨") st.stop() llm = HuggingFaceEndpoint( repo_id="meta-llama/Meta-Llama-3-8B-Instruct", huggingfacehub_api_token=st.secrets["HF_TOKEN"], temperature=0.1, max_new_tokens=2048, ) return llm def generating_results(context, Final_Query, llm): """Generates results using the loaded LLM.""" prompt = PromptTemplate( template=""" You are an expert in extracting data from User Requirement Specification (URS) documents. You are given: ## CONTEXT: {context} ## PLACEHOLDER-HINT DICTIONARY: {Final_Query} ## TASK: - Extract the exact values for the provided placeholders using the information from the relevant document chunks. - If the hint is "Not given", skip that placeholder. - For placeholders like "[Utility#]", return multiple values as "[Utility#1]", "[Utility#2]", etc. - Your final output MUST be a single, valid JSON object. - The keys of the JSON object must be the placeholders from the dictionary. - The values must be the extracted information. Do not add any extra text, explanations, or markdown formatting around the JSON. - Start your response directly with ```json and end it with ```. ## RESPONSE (must be a single JSON object): """, input_variables=['context', 'Final_Query'] ) chain = prompt | llm response = chain.invoke({ 'context': "\n".join([doc.page_content for doc in context]), 'Final_Query': Final_Query }) return response # --- Streamlit App UI --- if 'show_button' not in st.session_state: st.session_state.show_button = True # We need the secret to run, so we check for it first. if "HF_TOKEN" not in st.secrets: st.error("A Hugging Face Token is required to run this app. Please add it to your Space secrets in the 'Settings' tab.", icon="🔑") st.session_state.show_button = False if st.session_state.show_button: if st.button("✨ Start Extraction", type="primary"): with st.spinner("Calling the Llama 3 Inference API... This should be fast!"): try: # 1. Load the LLM via the API llm_extraction = get_llm() # 2. Call the generation function raw_response = generating_results(CONTEXT_DOCUMENTS, FINAL_QUERY, llm_extraction) st.subheader("Raw Model Output") st.text(raw_response) # 3. Safely parse the JSON from the response try: json_start = raw_response.find('{') json_end = raw_response.rfind('}') + 1 json_str = raw_response[json_start:json_end] result = json.loads(json_str) st.success("✅ Extraction Complete!") st.subheader("Parsed JSON Result") st.json(result) except Exception as e: st.error(f"⚠️ Failed to parse JSON from the model's response. Error: {e}") st.text_area("Model's Raw Response for Debugging:", raw_response, height=300) except Exception as e: st.error(f"An unexpected error occurred during the extraction process: {e}")