selim-ba commited on
Commit
d76410e
·
verified ·
1 Parent(s): cb81dc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -32,15 +32,18 @@ class SuperSmartAgent:
32
  ############## NODES ###################
33
  def check_reversed(state):
34
  question = state["question"]
35
- def is_mostly_non_words(text):
36
- words = text.split()
37
- english_like = sum(1 for w in words if re.match(r"^[a-zA-Z]+$", w))
38
- return english_like / max(len(words), 1) < 0.5
39
-
40
- if is_mostly_non_words(question):
41
- state["is_reversed"] = True
 
 
 
42
  else:
43
- state["is_reversed"] = False
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
- if "opposite of the word" in q:
55
- state["is_riddle"] = True
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):