Spaces:
Sleeping
Sleeping
Velayutham S commited on
Commit ·
3ebf645
1
Parent(s): 3890958
fix: Tamil to English RAG query translation for accurate retrieval
Browse files
app.py
CHANGED
|
@@ -57,8 +57,42 @@ def get_lang(lang):
|
|
| 57 |
if "English Only" in lang: return "Answer ONLY in English"
|
| 58 |
return "Answer in Tamil + English mix (Tanglish)"
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
def generate(message, mode, grade, subject, language, story_style):
|
| 61 |
-
|
|
|
|
| 62 |
ctx_text = f"Textbook Context:\n{ctx}" if ctx else "(Use general TN Board knowledge)"
|
| 63 |
system = SYSTEM_PROMPT.format(language=get_lang(language))
|
| 64 |
if mode == "📚 Chat Tutor":
|
|
|
|
| 57 |
if "English Only" in lang: return "Answer ONLY in English"
|
| 58 |
return "Answer in Tamil + English mix (Tanglish)"
|
| 59 |
|
| 60 |
+
# Tamil → English query mapping for better RAG retrieval
|
| 61 |
+
TAMIL_TO_ENGLISH = {
|
| 62 |
+
"தேவை விதி": "law of demand",
|
| 63 |
+
"தேவை": "demand",
|
| 64 |
+
"விநியோகம்": "supply",
|
| 65 |
+
"விநியோக விதி": "law of supply",
|
| 66 |
+
"இரட்டை பதிவு": "double entry",
|
| 67 |
+
"இரட்டை பதிவு முறை": "double entry bookkeeping",
|
| 68 |
+
"மொத்த உள்நாட்டு உற்பத்தி": "GDP gross domestic product",
|
| 69 |
+
"தொழில் முனைவோர்": "entrepreneur entrepreneurship",
|
| 70 |
+
"நுகர்வோர் உரிமைகள்": "consumer rights",
|
| 71 |
+
"பணவீக்கம்": "inflation",
|
| 72 |
+
"வங்கி": "bank banking",
|
| 73 |
+
"வரி": "tax taxation",
|
| 74 |
+
"இலாபம்": "profit",
|
| 75 |
+
"நஷ்டம்": "loss",
|
| 76 |
+
"சொத்து": "assets",
|
| 77 |
+
"பொறுப்பு": "liability",
|
| 78 |
+
"மூலதனம்": "capital",
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
def get_rag_query(message):
|
| 82 |
+
"""Convert Tamil query to English for better vector search"""
|
| 83 |
+
msg_lower = message.lower()
|
| 84 |
+
for tamil, english in TAMIL_TO_ENGLISH.items():
|
| 85 |
+
if tamil in message:
|
| 86 |
+
return english
|
| 87 |
+
# If mostly Tamil, use subject+grade as context
|
| 88 |
+
tamil_chars = sum(1 for c in message if '' <= c <= '')
|
| 89 |
+
if tamil_chars > len(message) * 0.3:
|
| 90 |
+
return message # Let Gemini embed handle it
|
| 91 |
+
return message
|
| 92 |
+
|
| 93 |
def generate(message, mode, grade, subject, language, story_style):
|
| 94 |
+
rag_query = get_rag_query(message)
|
| 95 |
+
ctx = rag_search(rag_query, grade=grade, subject=subject)
|
| 96 |
ctx_text = f"Textbook Context:\n{ctx}" if ctx else "(Use general TN Board knowledge)"
|
| 97 |
system = SYSTEM_PROMPT.format(language=get_lang(language))
|
| 98 |
if mode == "📚 Chat Tutor":
|