Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|