selim-ba commited on
Commit
b33ca49
·
verified ·
1 Parent(s): fd18c0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -6,6 +6,7 @@ import pandas as pd
6
 
7
  from langgraph.graph import StateGraph, END
8
  from typing import TypedDict
 
9
 
10
 
11
  # (Keep Constants as is)
@@ -31,8 +32,12 @@ class SuperSmartAgent:
31
  ############## NODES ###################
32
  def check_reversed(state):
33
  question = state["question"]
34
- reversed_text = question[::-1]
35
- if reversed_text.count(' ') > question.count(' '):
 
 
 
 
36
  state["is_reversed"] = True
37
  else:
38
  state["is_reversed"] = False
 
6
 
7
  from langgraph.graph import StateGraph, END
8
  from typing import TypedDict
9
+ import re
10
 
11
 
12
  # (Keep Constants as is)
 
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