-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtruthlayer.py
More file actions
62 lines (48 loc) · 1.24 KB
/
truthlayer.py
File metadata and controls
62 lines (48 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import hashlib
import json
from datetime import datetime
print("=== TruthLayer AI Trust Checker ===\n")
prompt = input("Enter prompt:\n")
ai_output = input("\nEnter AI output:\n")
confidence = 85
issues = []
text = ai_output.lower()
if "guaranteed" in text:
confidence -= 40
issues.append("Overconfident claim")
if "always" in text or "never" in text:
confidence -= 20
issues.append("Absolute statement")
if len(ai_output) < 15:
confidence -= 30
issues.append("Weak response")
if confidence < 0:
confidence = 0
if confidence > 70:
risk = "LOW"
elif confidence > 40:
risk = "MEDIUM"
else:
risk = "HIGH"
result = {
"trust_score": confidence,
"risk_level": risk,
"issues": issues if issues else ["No major issues"]
}
raw = json.dumps({
"prompt": prompt,
"output": ai_output,
"result": result
}, sort_keys=True)
proof = hashlib.sha256(raw.encode()).hexdigest()
receipt = {
"prompt": prompt,
"ai_output": ai_output,
"analysis": result,
"proof": proof,
"verified_by": "OpenGradient Alpha (tested)",
"note": "ModelHub integration currently blocked (Firebase key missing)",
"timestamp": str(datetime.now())
}
print("\n=== RESULT ===")
print(json.dumps(receipt, indent=2))