Spaces:
Runtime error
Runtime error
Download src/recommendation_engine/semantic_intent_classifier.py from InnoTrack/Graduation_Project-v1.2: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/InnoTrack/Graduation_Project-v1.2/resolve/main/src/recommendation_engine/semantic_intent_classifier.py
- Command line
-
hf download hf://spaces/InnoTrack/Graduation_Project-v1.2/src/recommendation_engine/semantic_intent_classifier.py
-
curl -L -o semantic_intent_classifier.py https://huggingface.co/spaces/InnoTrack/Graduation_Project-v1.2/resolve/main/src/recommendation_engine/semantic_intent_classifier.py
1.5 kB
| from src.recommendation_engine.llm_client import generate_text | |
| VALID_INTENTS = { | |
| "idea", | |
| "feature", | |
| "full_project", | |
| "chat" | |
| } | |
| def detect_intent_semantic(user_input: str, state: dict) -> str: | |
| prompt = f""" | |
| You are an intent classifier for a graduation project assistant. | |
| Classify the user intent into ONE of these: | |
| idea | |
| feature | |
| description | |
| full_project | |
| chat | |
| ================ CONTEXT ================= | |
| Current Project Title: | |
| {state.get("project_title") or "None"} | |
| Has Features: | |
| {"yes" if state.get("features") else "no"} | |
| Has Description: | |
| {"yes" if state.get("description") else "no"} | |
| ================ USER ================= | |
| "{user_input}" | |
| ================ RULES ================= | |
| - Asking for project ideas β idea | |
| - Asking for another/new idea β idea | |
| - Providing a project idea β feature | |
| - Asking for features β featuregenerate features | |
| - Asking for full project / full details β full_project | |
| - If unclear β chat | |
| IMPORTANT: | |
| Return ONLY ONE WORD from the list. | |
| """ | |
| result = generate_text(prompt, task="intent").lower().strip() | |
| result = result.split()[0].strip() | |
| if result in VALID_INTENTS: | |
| return result | |
| text = user_input.lower() | |
| if any(w in text for w in ["idea", "project", "suggest"]): | |
| return "idea" | |
| if any(w in text for w in ["feature"]): | |
| return "feature" | |
| if any(w in text for w in ["full", "all details", "complete"]): | |
| return "full_project" | |
| return "chat" | |