Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
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 |
|