Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,101 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
logs = []
|
| 7 |
-
|
| 8 |
-
logs.append(f"π Auditing {vendor_name}...")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
else:
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 33 |
-
gr.Markdown("
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
btn.click(
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def calculate_risk(data_type, users, location, use_case):
|
| 4 |
+
score = 0
|
| 5 |
+
reasons = []
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# 1. Data Sensitivity Scoring (nFADP Art. 5)
|
| 8 |
+
if data_type == "Public Data":
|
| 9 |
+
score += 1
|
| 10 |
+
elif data_type == "Internal/Private":
|
| 11 |
+
score += 3
|
| 12 |
+
elif data_type == "Sensitive / Biometric / Medical":
|
| 13 |
+
score += 10
|
| 14 |
+
reasons.append("π¨ **High Risk Data:** Processing sensitive personal data requires explicit consent (nFADP) and strict DPIA (EU AI Act).")
|
| 15 |
|
| 16 |
+
# 2. User Volume (Systemic Risk)
|
| 17 |
+
if users == "< 1,000 DAU":
|
| 18 |
+
score += 1
|
| 19 |
+
elif users == "1,000 - 50,000 DAU":
|
| 20 |
+
score += 3
|
| 21 |
+
elif users == "> 50,000 DAU":
|
| 22 |
+
score += 5
|
| 23 |
+
reasons.append("π **High Volume:** Systems with >50k users are often classified as 'Systemic Risk' under EU AI Act.")
|
| 24 |
|
| 25 |
+
# 3. Server Location (Cross-Border Transfer)
|
| 26 |
+
if location == "Switzerland (CH)":
|
| 27 |
+
score += 0
|
| 28 |
+
reasons.append("β
**Sovereign Hosting:** Data resides in Switzerland. nFADP compliant.")
|
| 29 |
+
elif location == "European Union (EU)":
|
| 30 |
+
score += 1
|
| 31 |
+
reasons.append("β
**Adequate Protection:** EU is on the Swiss FDPIC 'Safe Country' list.")
|
| 32 |
+
elif location == "USA (Cloud Act Scope)":
|
| 33 |
+
score += 5
|
| 34 |
+
reasons.append("β οΈ **US Cloud Act Risk:** Transfer requires TIA (Transfer Impact Assessment) and SCCs.")
|
| 35 |
+
elif location == "Other / Global":
|
| 36 |
+
score += 7
|
| 37 |
+
reasons.append("π¨ **Unknown Jurisdiction:** High risk of data sovereignty violation.")
|
| 38 |
+
|
| 39 |
+
# Calculate Verdict
|
| 40 |
+
if score >= 12:
|
| 41 |
+
tier = "TIER 4: UNACCEPTABLE / HIGH RISK"
|
| 42 |
+
color = "red"
|
| 43 |
+
action = "π STOP DEPLOYMENT. Requires full DPIA and Legal Review."
|
| 44 |
+
elif score >= 7:
|
| 45 |
+
tier = "TIER 3: SUBSTANTIAL RISK"
|
| 46 |
+
color = "orange"
|
| 47 |
+
action = "β οΈ PROCEED WITH CAUTION. Implement SCCs and Encryption."
|
| 48 |
else:
|
| 49 |
+
tier = "TIER 1: LOW RISK"
|
| 50 |
+
color = "green"
|
| 51 |
+
action = "β
APPROVED for Pilot. Standard monitoring applies."
|
| 52 |
|
| 53 |
+
# Formatted Output
|
| 54 |
+
report = f"""
|
| 55 |
+
## π‘οΈ Audit Verdict: <span style='color:{color}'>{tier}</span>
|
| 56 |
+
|
| 57 |
+
**Risk Score:** {score}/20
|
| 58 |
+
|
| 59 |
+
### π Compliance Actions Required:
|
| 60 |
+
{action}
|
| 61 |
+
|
| 62 |
+
### π Detected Risk Factors:
|
| 63 |
+
"""
|
| 64 |
+
for r in reasons:
|
| 65 |
+
report += f"\n- {r}"
|
| 66 |
+
|
| 67 |
+
return report
|
| 68 |
|
| 69 |
+
# --- UI Layout ---
|
| 70 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 71 |
+
gr.Markdown("""
|
| 72 |
+
# π¨π Swiss Risk Calculator
|
| 73 |
+
### nFADP & EU AI Act Compliance Engine
|
| 74 |
+
**Cata Risk Lab** | Zurich β’ London β’ Miami
|
| 75 |
+
""")
|
| 76 |
|
| 77 |
with gr.Row():
|
| 78 |
+
with gr.Column():
|
| 79 |
+
gr.Markdown("### 1. Deployment Details")
|
| 80 |
+
data_input = gr.Radio(
|
| 81 |
+
["Public Data", "Internal/Private", "Sensitive / Biometric / Medical"],
|
| 82 |
+
label="Data Classification (nFADP Art. 5)"
|
| 83 |
+
)
|
| 84 |
+
users_input = gr.Radio(
|
| 85 |
+
["< 1,000 DAU", "1,000 - 50,000 DAU", "> 50,000 DAU"],
|
| 86 |
+
label="Daily Active Users"
|
| 87 |
+
)
|
| 88 |
+
loc_input = gr.Radio(
|
| 89 |
+
["Switzerland (CH)", "European Union (EU)", "USA (Cloud Act Scope)", "Other / Global"],
|
| 90 |
+
label="Hosting Jurisdiction"
|
| 91 |
+
)
|
| 92 |
+
btn = gr.Button("π Run Compliance Audit", variant="primary")
|
| 93 |
+
|
| 94 |
+
with gr.Column():
|
| 95 |
+
gr.Markdown("### 2. Risk Assessment Report")
|
| 96 |
+
output_box = gr.Markdown()
|
| 97 |
|
| 98 |
+
btn.click(fn=calculate_risk, inputs=[data_input, users_input, loc_input], outputs=output_box)
|
| 99 |
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
demo.launch()
|