Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,15 +32,18 @@ class SuperSmartAgent:
|
|
| 32 |
############## NODES ###################
|
| 33 |
def check_reversed(state):
|
| 34 |
question = state["question"]
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
if
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
else:
|
| 43 |
-
state["
|
| 44 |
return state
|
| 45 |
|
| 46 |
def fix_question(state):
|
|
@@ -51,10 +54,8 @@ class SuperSmartAgent:
|
|
| 51 |
|
| 52 |
def check_riddle_or_trick(state):
|
| 53 |
q = state["question"].lower()
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
else:
|
| 57 |
-
state["is_riddle"] = False
|
| 58 |
return state
|
| 59 |
|
| 60 |
def solve_riddle(state):
|
|
|
|
| 32 |
############## NODES ###################
|
| 33 |
def check_reversed(state):
|
| 34 |
question = state["question"]
|
| 35 |
+
reversed_candidate = question[::-1]
|
| 36 |
+
reversed_words = reversed_candidate.split()
|
| 37 |
+
forward_words = question.split()
|
| 38 |
+
|
| 39 |
+
reversed_ratio = sum(1 for word in reversed_words if word.isalpha()) / len(reversed_words)
|
| 40 |
+
forward_ratio = sum(1 for word in forward_words if word.isalpha()) / len(forward_words)
|
| 41 |
+
|
| 42 |
+
if reversed_ratio > forward_ratio:
|
| 43 |
+
state["question"] = reversed_candidate
|
| 44 |
+
state["was_reversed"] = True
|
| 45 |
else:
|
| 46 |
+
state["was_reversed"] = False
|
| 47 |
return state
|
| 48 |
|
| 49 |
def fix_question(state):
|
|
|
|
| 54 |
|
| 55 |
def check_riddle_or_trick(state):
|
| 56 |
q = state["question"].lower()
|
| 57 |
+
keywords = ["opposite of", "if you understand", "riddle", "trick question", "what comes next", "i speak without"]
|
| 58 |
+
state["is_riddle"] = any(kw in q for kw in keywords)
|
|
|
|
|
|
|
| 59 |
return state
|
| 60 |
|
| 61 |
def solve_riddle(state):
|