Spaces:
Sleeping
Sleeping
Download modules/module_1_intent_router.py from Sepideh2027/PathogenAgent: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/Sepideh2027/PathogenAgent/resolve/main/modules/module_1_intent_router.py
- Command line
-
hf download hf://spaces/Sepideh2027/PathogenAgent/modules/module_1_intent_router.py
-
curl -L -o module_1_intent_router.py https://huggingface.co/spaces/Sepideh2027/PathogenAgent/resolve/main/modules/module_1_intent_router.py
2.26 kB
| # ========================================================== | |
| # PATHOGENAGENT - MODULE 1: INTENT ROUTER | |
| # ========================================================== | |
| import re | |
| from typing import Dict, List, Tuple | |
| class IntentRouter: | |
| """تشخیص نوع سوال و تعیین ابزارهای مورد نیاز""" | |
| def __init__(self): | |
| self.variant_patterns = [ | |
| r'c\.[0-9]+[a-z]?[0-9]*', | |
| r'p\.[a-z][0-9]+[a-z]', | |
| r'rs[0-9]+', | |
| r'[a-z]+[0-9]+[a-z]', | |
| r'[A-Z][0-9]+[A-Z]' | |
| ] | |
| self.gene_list = [ | |
| "brca1", "brca2", "cftr", "tp53", "egfr", "kras", | |
| "alk", "ros1", "her2", "apoe", "mlh1", "msh2", | |
| "pten", "atm", "chek2", "palb2", "vhl" | |
| ] | |
| self.pathogen_keywords = [ | |
| "virus", "genome", "sequence", "organism", "strain", | |
| "sars", "cov", "ebola", "influenza", "mers", "hiv", | |
| "dengue", "zika", "tuberculosis", "malaria" | |
| ] | |
| def detect_intent(self, query: str) -> Dict: | |
| """تشخیص نوع سوال""" | |
| q = query.lower().strip() | |
| confidence = 0.0 | |
| intent = "general" | |
| tools = ["PubMed"] | |
| # بررسی واریانت | |
| for pattern in self.variant_patterns: | |
| if re.search(pattern, q, re.IGNORECASE): | |
| confidence = 0.9 | |
| intent = "variant" | |
| tools = ["PubMed", "ClinVar"] | |
| break | |
| # بررسی ژن | |
| if confidence < 0.7: | |
| for gene in self.gene_list: | |
| if gene in q: | |
| confidence = 0.7 | |
| intent = "gene" | |
| tools = ["PubMed", "Gene"] | |
| break | |
| # بررسی پاتوژن | |
| if confidence < 0.5: | |
| for keyword in self.pathogen_keywords: | |
| if keyword in q: | |
| confidence = 0.8 | |
| intent = "pathogen" | |
| tools = ["PubMed", "GenBank"] | |
| break | |
| return { | |
| "query": query, | |
| "intent": intent, | |
| "confidence": confidence, | |
| "required_tools": tools | |
| } |