Toumaima commited on
Commit
4d91f18
·
verified ·
1 Parent(s): a47a2c4

Update app.py

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