Toumaima commited on
Commit
a47a2c4
·
verified ·
1 Parent(s): 64a9f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -46
app.py CHANGED
@@ -63,52 +63,58 @@ class BasicAgent:
63
  return context # Fallback to context if QA fails
64
 
65
  def handle_logic_riddles(self, question: str) -> str | None:
66
- q = question.lower().strip()
67
-
68
- logic_patterns = [
69
- {
70
- "pattern": r"opposite of the word ['\"]?left['\"]?",
71
- "answer": "right"
72
- },
73
- {
74
- "pattern": r"what comes after ['\"]?a['\"]?",
75
- "answer": "b"
76
- },
77
- {
78
- "pattern": r"first letter of the alphabet",
79
- "answer": "a"
80
- },
81
- {
82
- "pattern": r"what is the color of the clear sky",
83
- "answer": "blue"
84
- },
85
- {
86
- "pattern": r"how many sides does a triangle have",
87
- "answer": "3"
88
- },
89
- {
90
- "pattern": r"how many legs does a spider have",
91
- "answer": "8"
92
- },
93
- {
94
- "pattern": r"what is 2 \+ 2",
95
- "answer": "4"
96
- },
97
- {
98
- "pattern": r"what is the opposite of ['\"]?up['\"]?",
99
- "answer": "down"
100
- },
101
- {
102
- "pattern": r"if you understand this sentence.*opposite.*left",
103
- "answer": "right"
104
- }
105
- ]
106
-
107
- for item in logic_patterns:
108
- if re.search(item["pattern"], q, re.IGNORECASE):
109
- return item["answer"]
110
-
111
- return None
 
 
 
 
 
 
112
 
113
 
114
  def __call__(self, question: str, video_path: str = None) -> str:
 
63
  return context # Fallback to context if QA fails
64
 
65
  def handle_logic_riddles(self, question: str) -> str | None:
66
+ import string
67
+
68
+ # Normalize the input
69
+ q = question.lower().strip()
70
+ q = q.translate(str.maketrans("", "", string.punctuation)) # remove punctuation
71
+ q = re.sub(r"\s+", " ", q) # normalize multiple spaces
72
+
73
+ logic_patterns = [
74
+ {
75
+ "pattern": r"opposite of the word left",
76
+ "answer": "right"
77
+ },
78
+ {
79
+ "pattern": r"what comes after a",
80
+ "answer": "b"
81
+ },
82
+ {
83
+ "pattern": r"first letter of the alphabet",
84
+ "answer": "a"
85
+ },
86
+ {
87
+ "pattern": r"what is the color of the clear sky",
88
+ "answer": "blue"
89
+ },
90
+ {
91
+ "pattern": r"how many sides does a triangle have",
92
+ "answer": "3"
93
+ },
94
+ {
95
+ "pattern": r"how many legs does a spider have",
96
+ "answer": "8"
97
+ },
98
+ {
99
+ "pattern": r"what is 2 \+ 2",
100
+ "answer": "4"
101
+ },
102
+ {
103
+ "pattern": r"what is the opposite of up",
104
+ "answer": "down"
105
+ },
106
+ {
107
+ "pattern": r"if you understand this sentence.*opposite.*left",
108
+ "answer": "right"
109
+ }
110
+ ]
111
+
112
+ for item in logic_patterns:
113
+ if re.search(item["pattern"], q, re.IGNORECASE):
114
+ return item["answer"]
115
+
116
+ return None
117
+
118
 
119
 
120
  def __call__(self, question: str, video_path: str = None) -> str: