Download agents/proof_builder.py from dipan004/Proofly: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/spaces/dipan004/Proofly/resolve/main/agents/proof_builder.py
- Command line
-
hf download hf://spaces/dipan004/Proofly/agents/proof_builder.py
-
curl -L -o proof_builder.py https://huggingface.co/spaces/dipan004/Proofly/resolve/main/agents/proof_builder.py
2.34 kB
| """ | |
| Proof Builder Agent | |
| Assembles final proof object from validated components. | |
| """ | |
| from typing import Dict, Any | |
| import uuid | |
| from core.agent_base import Agent | |
| from core.errors import ProofSystemError | |
| from models.proof import Proof | |
| class ProofBuilderAgent(Agent): | |
| """ | |
| Combines hash, metadata, and validation results into a Proof object. | |
| """ | |
| def execute(self, input_data: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Build final proof object. | |
| Expected input_data: | |
| { | |
| "content_hash": str, | |
| "hash_algorithm": str, | |
| "metadata": dict, | |
| "validation_status": str, | |
| "extracted_text": str | None, | |
| "ocr_engine": str | None, | |
| "ocr_status": str | None, | |
| ... | |
| } | |
| Returns: | |
| { | |
| "proof": Proof, | |
| "proof_id": str | |
| } | |
| """ | |
| try: | |
| # Generate unique proof ID | |
| proof_id = self._generate_proof_id() | |
| # Extract required fields | |
| metadata = input_data.get("metadata", {}) | |
| # Build proof object (including OCR fields) | |
| proof = Proof( | |
| proof_id=proof_id, | |
| content_hash=input_data.get("content_hash"), | |
| hash_algorithm=input_data.get("hash_algorithm"), | |
| content_type=metadata.get("content_type"), | |
| content_size=metadata.get("content_size"), | |
| timestamp=metadata.get("created_at"), | |
| validation_status=input_data.get("validation_status"), | |
| metadata=metadata, | |
| extracted_text=input_data.get("extracted_text"), | |
| ocr_engine=input_data.get("ocr_engine"), | |
| ocr_status=input_data.get("ocr_status") | |
| ) | |
| return { | |
| "proof": proof, | |
| "proof_id": proof_id | |
| } | |
| except Exception as e: | |
| raise ProofSystemError(f"Proof building failed: {str(e)}") from e | |
| def _generate_proof_id(self) -> str: | |
| """ | |
| Generate unique proof identifier. | |
| Returns: | |
| UUID string | |
| """ | |
| return str(uuid.uuid4()) |