From f71ee27d5381983e993b25acfb12a6e7b4678066 Mon Sep 17 00:00:00 2001 From: vidit choudhary <153429790+vidit-16@users.noreply.github.com> Date: Wed, 7 Oct 2026 06:47:56 +0530 Subject: [PATCH] Give the models the campus place names; read romanised Kannada MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Voice tests filled "Nannagai Canteen" (nannagai means "to me") and turned मेक पार्किंग into plain "Parking". - Every prompt now lists the campus places and asks for the listed name whenever one is meant, in any spelling or language, and explains that nanage, nannagai, mujhe, mera and the like are never part of a name. - The rules read Whisper's romanised Kannada and Hindi: common colour and item words (kappu, neeli, pers, botal) and more spellings of nanage. --- app.py | 22 +++++++++++++++++++--- tests/test_app.py | 10 ++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index dd7e7f1..ad190d8 100644 --- a/app.py +++ b/app.py @@ -1484,6 +1484,7 @@ def reject_claim(claim_id): "mil", "mila", "mili", "mile", "gaya", "gayi", "gya", "gyi", "hogaya", "hogya", "raha", "rahi", "diya", "liya", "kho", "gum", "ko", "ka", "ki", "ke", "se", "par", "pe", "aaj", "kal", "yeh", "ye", "woh", "wo", "nanna", "nange", "nanu", "ondu", "alli", "sikkitu", "sikkide", "hoyitu", "kaledu", "kalkonde", "ivattu", "ninne", "hatra", "hathra", "andar", "bahar", "paas", + "nanagai", "nannagai", "nanngai", "nanage", "nangai", "nanna", "undu", "sikkida", "sikkidu", "sikkithu", "aytu", # The same words in Devanagari and Kannada script. "मुझे", "मेरा", "मेरी", "मेरे", "मैंने", "एक", "में", "है", "था", "थी", "मिल", "मिला", "मिली", "मिले", "गया", "गयी", "गई", "खो", "गुम", "को", "का", "की", "के", "से", "पर", "आज", "कल", "यह", "वह", "पास", @@ -1514,11 +1515,20 @@ def model_error(exc): return f"{type(exc).__name__}: {exc}"[:300] +# Common item words in romanised Kannada and Hindi, and how speech-to-text spells them. +MIXED_ITEM_WORDS = { + "kappu": "black", "kala": "black", "kaala": "black", "kempu": "red", "laal": "red", "neeli": "blue", + "nili": "blue", "neela": "blue", "hasiru": "green", "hara": "green", "bili": "white", "safed": "white", + "pers": "purse", "parse": "purse", "batli": "bottle", "botal": "bottle", "chhata": "umbrella", + "chabi": "key", "kitab": "book", "paani": "water", "neeru": "water", +} + + def parse_mixed_rules(text, status): """A Hinglish or Kanglish sentence without a model: drop the joining words and the places.""" # Split on spaces: vowel signs in Indian scripts are not word characters to a regex. words = [w.strip(".,!?;:'\"") for w in text.split()] - words = [w for w in words if w and w.lower() not in MIXED_WORDS] + words = [MIXED_ITEM_WORDS.get(w.lower(), w) for w in words if w and w.lower() not in MIXED_WORDS] _, rest = campus.split_search(" ".join(words)) title = " ".join(w for w in rest.split() if w not in STOP_WORDS)[:80].strip() first = campus.find_places(text) @@ -1557,6 +1567,12 @@ def parse_mixed_rules(text, status): "A purse, wallet, ID card or bus pass is Wallet & ID; a bottle, bag or umbrella is Accessories. " "Always reply in English. Found means they found or picked up something (found, mila, mili, " "mil gaya, sikkitu, sikkide); Lost means they lost it (lost, kho gaya, gum gaya, kaledu hoyitu). " + "Words like nanage, nannagai, nanna, nanu, ondu, alli, hatra, mujhe, mera, meri, ek, mein, paas mean " + "me, my, one, in or near: they are never part of an item or a place name. " + "The campus places are: " + ", ".join(sorted({p["short"] for p in campus.CAMPUS["places"]})) + ". " + "Departments, labs, the library, the bank and offices are in the Main Block. When the student names " + "one of these places, however it is spelt or in whatever language (e.g. मेक पार्किंग is Mech Parking, " + "ಕ್ಯಾಂಟೀನ್ is Canteen), write that place's name exactly as listed. " ) REPORT_PROMPT = ( "Extract a campus lost-and-found report. " + LANGUAGES_NOTE + @@ -1831,7 +1847,7 @@ def parse_report(): "A student describes what they lost and where they went on campus. " + LANGUAGES_NOTE + "Reply with JSON only: " '{"item": the lost item in a few English words or "", ' - '"places": the campus places they mention, in the order they went, each in English, ' + '"places": the campus places they mention, in the order they went, each by its name from the list, ' '"when": "today", "yesterday" or "week"}. ' "Use the place names as said, translated to English; do not add places that are not mentioned." ) @@ -1895,7 +1911,7 @@ def parse_retrace(): 'computer science lab.\" Not in the first person, ' f'"category": one of {REPORT_CATEGORIES}, ' '"location": where the item was, in English, or "", ' - '"places": every campus place they mention, in English, in the order they went there, ' + '"places": every campus place they mention, by its name from the list, in the order they went there, ' '"when": "today", "yesterday" or "week"}. Do not invent anything they did not say.' ) VOICE_MAX_BYTES = 2 * 1024 * 1024 diff --git a/tests/test_app.py b/tests/test_app.py index 19153b1..3f8cb5a 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -999,6 +999,16 @@ def test_a_misheard_kannada_canteen_still_counts(self): import campus self.assertEqual(campus.resolve_place("ನನಗೆ ಕೆಂಟಿನ್ ಒಂದು ಪರ್ಸ್ ಸಿಕಿಡೆ")["candidates"], ["canteen", "puff-shop", "nandini"]) + def test_romanised_kannada_from_whisper(self): + fields = parse_report_rules("NANNGAI CANTEEN HATRA UNDU KAPPU PERS SIKKIDA") + self.assertEqual((fields["title"], fields["category"], fields["status"], fields["location"]), + ("Black purse", "Wallet & ID", "Found", "Canteen")) + + def test_the_prompts_list_the_campus_places(self): + for prompt in (app_module.REPORT_PROMPT, app_module.RETRACE_PROMPT, app_module.VOICE_PROMPT): + self.assertIn("Mech Parking", prompt) + self.assertIn("nannagai", prompt) + def test_hinglish_and_kanglish_without_a_model(self): found = parse_report_rules("Mujhe computer lab Mein Ek key Mili Hai") self.assertEqual((found["title"], found["status"], found["category"]), ("Key", "Found", "Keys"))