FaustDerLegende's picture
Upload folder using huggingface_hub (part 84)
693bf28 verified
Raw History Blame Contribute Delete
3.51 kB
"""PCB Analyzer Orchestrator Entry Point for Collector Lite & Recycler Portal."""
from __future__ import annotations
from typing import Any
from .model_client import BaseModelClient, MockModelClient, Detection
from .purity_assay import assay_pcb, assess_bis_discrepancy, AssayedBoard
from .vernacular_voice import generate_vernacular_voice_alert, VoiceAlert
class PCBAnalyzer:
"""Single unified orchestrator for PCB micro-component purity assaying."""
def __init__(self, model_client: BaseModelClient | None = None):
self.model_client = model_client or MockModelClient()
def analyze_board(
self,
front_image: Any,
back_image: Any | None = None,
base_price: float = 100.0,
form_factor: str = "desktop_atx",
lang: str = "hi",
) -> dict[str, Any]:
"""Perform 2-photo workflow PCB component purity assaying."""
# Stage 1: Front side detection
detections_front = self.model_client.predict(front_image)
# Stage 2: Back side detection (if provided)
detections_back = []
if back_image is not None:
detections_back = self.model_client.predict(back_image)
all_detections = detections_front + detections_back
# Run Board Integrity Score assay
assayed: AssayedBoard = assay_pcb(
detections=all_detections,
base_price=base_price,
form_factor=form_factor,
)
# Generate vernacular voice alert
voice_alert: VoiceAlert = generate_vernacular_voice_alert(
bis_band=assayed.status_band,
adjusted_price=assayed.adjusted_price,
lang=lang,
)
return {
"form_factor": assayed.form_factor,
"board_integrity_score": assayed.board_integrity_score,
"base_price": assayed.base_price,
"adjusted_price": assayed.adjusted_price,
"price_floor": assayed.price_floor,
"status_band": assayed.status_band,
"detected_counts": assayed.detected_counts,
"expected_counts": assayed.expected_counts,
"fraud_desoldered_pads": assayed.fraud_desoldered_pads,
"factory_unpopulated_pads": assayed.factory_unpopulated_pads,
"occluded_regions": assayed.occluded_regions,
"voice_alert": {
"lang": voice_alert.lang,
"transcript": voice_alert.transcript,
"audio_fallback_path": voice_alert.audio_fallback_path,
},
}
def verify_intake_discrepancy(
self,
collector_bis: float,
recycler_front_image: Any,
recycler_back_image: Any | None = None,
form_factor: str = "desktop_atx",
) -> dict[str, Any]:
"""Verify intake lot discrepancy at Recycler Portal against collector BIS."""
recycler_analysis = self.analyze_board(
front_image=recycler_front_image,
back_image=recycler_back_image,
form_factor=form_factor,
)
recycler_bis = recycler_analysis["board_integrity_score"]
status = assess_bis_discrepancy(collector_bis, recycler_bis)
return {
"collector_bis": collector_bis,
"recycler_bis": recycler_bis,
"bis_delta": round(collector_bis - recycler_bis, 1),
"discrepancy_status": status, # "pass", "advisory_flag", "critical_fraud_alert"
"recycler_assay": recycler_analysis,
}