Spaces:
Running
Running
| # src/intent.py | |
| def detect_intent(text: str) -> str: | |
| """ | |
| Fast rule-based intent detection. | |
| Returns one of: "code", "math", "civics", "exam_prep", "general". | |
| """ | |
| if not text: | |
| return "general" | |
| t = text.lower() | |
| # Code-related keywords | |
| code_keys = ["python", "code", "error", "function", "class", "script", "import", "stack trace", "traceback", "bug"] | |
| if any(k in t for k in code_keys): | |
| return "code" | |
| # Math keywords | |
| math_keys = ["solve", "equation", "calculate", "simplify", "factor", "integrate", "differentiate", "sum", "prove", "find x", "x +"] | |
| if any(k in t for k in math_keys): | |
| return "math" | |
| # Civics / SST keywords (class 10) | |
| civics_keys = ["civics", "democracy", "constitution", "rights", "ncert", "class 10", "class 10th", "social studies", "sst"] | |
| if any(k in t for k in civics_keys): | |
| return "civics" | |
| # Exam prep keywords | |
| exam_keys = ["important questions", "exam", "board", "revision", "prepare", "question paper", "important", "mcq", "short answer"] | |
| if any(k in t for k in exam_keys): | |
| return "exam_prep" | |
| # Default | |
| return "general" | |