Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion backend/app/api/routes/frameworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

from app.api.dependencies import get_current_user
from app.core.database import get_db
from app.models.document import Document, DocumentDefinition
from app.models.framework import Framework
from app.models.user import User
from app.schemas.framework import FrameworkResponse
from app.schemas.framework import (
AddFrameworkRequest,
AvailableFrameworkResponse,
FrameworkResponse,
)
from app.services.seed import SEED_FRAMEWORKS, _load_knowledge

router = APIRouter(prefix="/api/frameworks", tags=["frameworks"])

Expand All @@ -34,6 +40,57 @@ def list_frameworks(
return [_to_response(fw) for fw in frameworks]


@router.get("/available", response_model=list[AvailableFrameworkResponse])
def list_available_frameworks(
db: Session = Depends(get_db),
_current_user: User = Depends(get_current_user),
):
existing_names = {name for (name,) in db.query(Framework.name).all()}
return [
{"name": fw["name"], "description": fw["description"], "category": fw["category"]}
for fw in SEED_FRAMEWORKS
if fw["name"] not in existing_names and fw["name"] != "EU AI Act"
]


@router.post("", response_model=FrameworkResponse)
def add_framework(
body: AddFrameworkRequest,
db: Session = Depends(get_db),
_current_user: User = Depends(get_current_user),
):
seed_data = next((fw for fw in SEED_FRAMEWORKS if fw["name"] == body.name), None)
if not seed_data:
raise HTTPException(status_code=404, detail="Framework not found in catalogue")

if db.query(Framework).filter(Framework.name == body.name).first():
raise HTTPException(status_code=409, detail="Framework already exists")

fw = Framework(
name=seed_data["name"],
description=seed_data["description"],
category=seed_data["category"],
status=seed_data["status"],
content=_load_knowledge(seed_data["name"]),
)
db.add(fw)
db.flush()

for doc_data in seed_data["documents"]:
db.add(
DocumentDefinition(
framework_id=fw.id,
name=doc_data["name"],
description=doc_data["description"],
article=doc_data["article"],
)
)

db.commit()
db.refresh(fw)
return _to_response(fw)


@router.get("/{framework_id}", response_model=FrameworkResponse)
def get_framework(
framework_id: uuid.UUID,
Expand All @@ -44,3 +101,25 @@ def get_framework(
if not fw:
raise HTTPException(status_code=404, detail="Framework not found")
return _to_response(fw)


@router.delete("/{framework_id}")
def delete_framework(
framework_id: uuid.UUID,
db: Session = Depends(get_db),
_current_user: User = Depends(get_current_user),
):
fw = db.query(Framework).filter(Framework.id == framework_id).first()
if not fw:
raise HTTPException(status_code=404, detail="Framework not found")

if fw.name == "EU AI Act":
raise HTTPException(status_code=403, detail="This framework cannot be removed")

def_ids = [d.id for d in fw.document_definitions]
if def_ids:
db.query(Document).filter(Document.definition_id.in_(def_ids)).delete()

db.delete(fw)
db.commit()
return {"detail": "Framework deleted"}
10 changes: 10 additions & 0 deletions backend/app/schemas/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from pydantic import BaseModel, ConfigDict


class AvailableFrameworkResponse(BaseModel):
name: str
description: str
category: str


class AddFrameworkRequest(BaseModel):
name: str


class FrameworkResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)

Expand Down
70 changes: 0 additions & 70 deletions backend/app/services/sample_evidence_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,74 +760,4 @@
"undp-framework-alignment-FA-15-0": "The system is registered in the EU AI database with all required fields completed, including provider and deployer information.",
"undp-framework-alignment-FA-16-0": "A Council of Europe HUDERIA-style assessment has been conducted, addressing human rights and democracy impacts.",
"undp-framework-alignment-FA-17-0": "The system complies with the Council of Europe AI Convention provisions on transparency, oversight, and accountability.",
# =========================================================================
# ENVIRONMENTAL IMPACT FRAMEWORK — Energy & Carbon (Principle 1-2)
# =========================================================================
"env-energy-carbon-EC-01-0": "Training energy was measured at 850 kWh for the initial model training run using GPU cluster power monitoring.",
"env-energy-carbon-EC-01-1": "The training energy mix comprises 78% renewable sources (wind and solar) from the data centre's certified green tariff.",
"env-energy-carbon-EC-02-0": "Inference energy is monitored per server; each recognition consumes approximately 0.003 kWh including camera and edge processing.",
"env-energy-carbon-EC-02-1": "Energy-per-query is tracked as a KPI; current rate is 10.8 kJ per recognition event including all system components.",
"env-energy-carbon-EC-03-0": "Total carbon footprint is estimated at 420 kg CO2e for training and 1.2 tonnes CO2e annually for inference across all sites.",
"env-energy-carbon-EC-03-1": "Scope 1 emissions are zero; Scope 2 covers data centre electricity; Scope 3 includes hardware manufacturing and logistics.",
"env-energy-carbon-EC-04-0": "A carbon reduction target of 20% by 2027 has been set, with progress reviewed quarterly against the baseline.",
"env-energy-carbon-EC-04-1": "Progress is tracked via quarterly carbon accounting; current trajectory shows a 12% reduction achieved since baseline.",
"env-energy-carbon-EC-05-0": "85% of operational energy comes from certified renewable sources; the target is 100% renewable by 2027.",
"env-energy-carbon-EC-05-1": "A commitment to increase renewable usage by 5% annually is documented in the environmental management plan.",
"env-energy-carbon-EC-06-0": "Residual emissions are offset through verified Gold Standard carbon credits; offset certificates are retained for audit.",
# =========================================================================
# ENVIRONMENTAL IMPACT FRAMEWORK — Hardware (Principle 3)
# =========================================================================
"env-hardware-HW-01-0": "Hardware selection prioritised NVIDIA T4 GPUs for their inference efficiency, consuming 70W versus 250W for alternatives.",
"env-hardware-HW-01-1": "Energy-efficient edge processing units reduce data centre load by performing initial face detection at the camera location.",
"env-hardware-HW-02-0": "GPU utilisation is monitored; inference workloads are batched during peak hours to maintain above 60% utilisation.",
"env-hardware-HW-02-1": "Off-peak workloads including model evaluation and reporting are scheduled for nighttime when renewable energy availability peaks.",
"env-hardware-HW-03-0": "Hardware refresh cycles are set at five years; servers are refurbished and redeployed to non-critical workloads after primary use.",
"env-hardware-HW-03-1": "Camera hardware is designed for a seven-year lifespan with modular lens replacement to extend operational life.",
"env-hardware-HW-04-0": "E-waste is managed through certified WEEE recycling partners with documented chain-of-custody and material recovery rates above 95%.",
"env-hardware-HW-04-1": "Hazardous materials in hardware are tracked via supplier declarations; RoHS compliance is verified for all components.",
"env-hardware-HW-05-0": "Supply chain sustainability is assessed during procurement; camera and server vendors provide annual sustainability reports.",
# =========================================================================
# ENVIRONMENTAL IMPACT FRAMEWORK — Data Management (Principle 4)
# =========================================================================
"env-data-management-DM-01-0": "Data storage efficiency is maximised by storing only facial templates (512 bytes each) rather than raw images after enrolment.",
"env-data-management-DM-01-1": "A retention policy automatically purges templates of departed employees within 30 days, minimising storage footprint.",
"env-data-management-DM-02-0": "Data transfer is minimised through edge processing; only compact feature vectors are transmitted to the central server.",
"env-data-management-DM-02-1": "Network transfer environmental cost is negligible due to small payload sizes (under 2 KB per recognition event).",
"env-data-management-DM-03-0": "Data centres are selected based on PUE rating (target below 1.3) and proximity to deployment sites to minimise latency and transfer.",
"env-data-management-DM-03-1": "Data centres are located in northern Europe to benefit from cooler ambient temperatures and higher renewable energy availability.",
"env-data-management-DM-04-0": "Data centre water usage effectiveness (WUE) is below 0.5 L/kWh, using free-cooling for 80% of the year.",
"env-data-management-DM-04-1": "Water-efficient cooling is prioritised; adiabatic cooling is used only during peak summer temperatures.",
# =========================================================================
# ENVIRONMENTAL IMPACT FRAMEWORK — Model Efficiency (Principle 5)
# =========================================================================
"env-model-efficiency-ME-01-0": "The model size (25M parameters) is justified by the accuracy requirements; a smaller MobileNet variant was evaluated but fell below the FAR threshold.",
"env-model-efficiency-ME-01-1": "Three smaller architectures were benchmarked; the selected model offers the best accuracy-to-compute ratio for the deployment scenario.",
"env-model-efficiency-ME-02-0": "Training efficiency uses mixed-precision (FP16) training, reducing GPU memory usage by 40% and training time by 30%.",
"env-model-efficiency-ME-02-1": "All training runs are documented with energy consumption, duration, and accuracy metrics to track efficiency improvements.",
"env-model-efficiency-ME-03-0": "Inference is optimised using TensorRT quantisation (INT8), reducing latency by 60% and energy consumption by 50%.",
"env-model-efficiency-ME-03-1": "The accuracy loss from INT8 quantisation is less than 0.1% FAR, validated as acceptable for the access control use case.",
"env-model-efficiency-ME-04-0": "Model retraining occurs biannually rather than continuously, using incremental fine-tuning on new enrolment data only.",
"env-model-efficiency-ME-04-1": "Incremental fine-tuning consumes 15% of the energy of full retraining while maintaining equivalent accuracy performance.",
"env-model-efficiency-ME-05-0": "Environmental efficiency is tracked as recognitions-per-kWh; current performance is 333 authentications per kWh.",
# =========================================================================
# ENVIRONMENTAL IMPACT FRAMEWORK — Lifecycle (Principle 3, 6)
# =========================================================================
"env-lifecycle-LC-01-0": "A lifecycle assessment covers the system from hardware manufacture through operation to decommissioning and disposal.",
"env-lifecycle-LC-01-1": "Embodied emissions from hardware manufacturing account for approximately 35% of the total lifecycle carbon footprint.",
"env-lifecycle-LC-02-0": "The decommissioning plan specifies secure data deletion, hardware recycling, and camera removal procedures.",
"env-lifecycle-LC-02-1": "Data deletion follows NIST 800-88 guidelines; hardware is sent to certified recycling facilities with documented material recovery.",
"env-lifecycle-LC-03-0": "Vendor sustainability is evaluated during procurement; data centre providers must demonstrate PUE below 1.3 and renewable energy usage.",
"env-lifecycle-LC-03-1": "SLA environmental criteria include uptime efficiency, power usage targets, and annual sustainability reporting obligations.",
"env-lifecycle-LC-04-0": "Circular economy practices include hardware refurbishment, component reuse, and material recovery at end of life.",
# =========================================================================
# ENVIRONMENTAL IMPACT FRAMEWORK — Monitoring (Principle 6)
# =========================================================================
"env-monitoring-EM-01-0": "Environmental KPIs include energy-per-recognition, total carbon emissions, hardware utilisation rate, and renewable energy percentage.",
"env-monitoring-EM-01-1": "KPIs are reviewed quarterly with annual targets set during the environmental management planning cycle.",
"env-monitoring-EM-02-0": "An annual environmental report discloses the system's energy consumption, carbon footprint, and sustainability initiatives.",
"env-monitoring-EM-02-1": "Reporting follows the GHG Protocol for carbon accounting and references ISO 14001 for environmental management practices.",
"env-monitoring-EM-03-0": "Continuous improvement identifies opportunities such as model compression, hardware upgrades, and cooling optimisation each year.",
"env-monitoring-EM-03-1": "Lessons learned from each improvement initiative are documented and shared across sites to accelerate sustainability gains.",
"env-monitoring-EM-04-0": "Environmental regulatory compliance is monitored; the system meets EU Energy Efficiency Directive requirements for ICT equipment.",
"env-monitoring-EM-05-0": "Sustainability targets are integrated into the project's KPI framework and reported alongside operational and compliance metrics.",
}
Loading
Loading