hoangs commited on
Commit
f59a827
·
verified ·
1 Parent(s): 5056f6c

Upload model.py

Browse files
Files changed (1) hide show
  1. model.py +45 -0
model.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import TypedDict
2
+
3
+ class SafetyResult(TypedDict):
4
+ safe: bool
5
+ reason: str
6
+
7
+ UNSAFE_KEYWORDS = [
8
+ "đốt",
9
+ "cháy",
10
+ "nổ",
11
+ "phá hủy",
12
+ "phá hoại",
13
+ "đập vỡ",
14
+ "làm đau",
15
+ "tấn công",
16
+ "giết",
17
+ "cầm dao",
18
+ "tắt báo cháy",
19
+ ]
20
+
21
+ def check_safety(command: str) -> SafetyResult:
22
+ """Check whether a Vietnamese command is safe for a home robot to execute."""
23
+ text = command.lower()
24
+
25
+ for word in UNSAFE_KEYWORDS:
26
+ if word in text:
27
+ return {
28
+ "safe": False,
29
+ "reason": f"Command contains unsafe keyword: '{word}'",
30
+ }
31
+
32
+ # default: safe
33
+ return {
34
+ "safe": True,
35
+ "reason": "No unsafe patterns detected",
36
+ }
37
+
38
+ if __name__ == "__main__":
39
+ tests = [
40
+ "Bật đèn phòng khách",
41
+ "Đốt rèm cửa đi",
42
+ "Mang dao vào phòng khách",
43
+ ]
44
+ for t in tests:
45
+ print(t, "->", check_safety(t))