Spaces:
Sleeping
Sleeping
Update app.py (#9)
Browse files- Update app.py (585eaf460cc7814227fbb88665a71263cb99110a)
5 unmodified lines67891011182 unmodified lines1941951961971981992002012022035 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"YOUTUBE_RE = re.compile(r"https?://(?:www\.)?youtube\.com/watch\?v=[\w-]+")NUM_WORDS = {"zero":"0","one":"1","two":"2","three":"3","four":"4","five":"5",182 unmodified linesspecies.add("giant petrel")return len(species)# change the template call to pass task_id as second argdef __call__(self, question: str, task_id: str | None = None) -> str:ql = question.lower()# 0) YouTube special-case: count distinct bird species from descriptionm = YOUTUBE_RE.search(question)if m:5 unmodified lines6789101112182 unmodified lines1951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432445 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"YOUTUBE_RE = re.compile(r"https?://(?:www\.)?youtube\.com/watch\?v=[\w-]+")REV_INSTR_RX = re.compile(r'opposite of the word ["“]?([A-Za-z]+)["”]?', re.I)NUM_WORDS = {"zero":"0","one":"1","two":"2","three":"3","four":"4","five":"5",182 unmodified linesspecies.add("giant petrel")return len(species)def _opposite_word(self, w: str) -> str | None:pairs = {"left": "right", "right": "left","up": "down", "down": "up","true": "false", "false": "true","open": "closed", "closed": "open","on": "off", "off": "on","start": "stop", "stop": "start","yes": "no", "no": "yes","north": "south", "south": "north","east": "west", "west": "east",}return pairs.get(w.lower())def _answer_from_reversed_instruction(self, q: str) -> str | None:# 1) reverse the whole promptrev = q[::-1]# 2) normalize quotesnorm = rev.replace("’", "'").replace("“", '"').replace("”", '"')# Case A: "opposite of the word "<X>""m = REV_INSTR_RX.search(norm)if m:target = m.group(1)opp = self._opposite_word(target)if opp:return opp # bare string, e.g., "right"# Case B: simple "write <X>" pattern after reversingm2 = re.search(r'^\s*write\s+["\']?([A-Za-z0-9\-]+)["\']?\s*$', norm.strip(), re.I)if m2:return m2.group(1)return None# change the template call to pass task_id as second argdef __call__(self, question: str, task_id: str | None = None) -> str:ql = question.lower()# NEW: reversed-instruction puzzle handlerrev_ans = self._answer_from_reversed_instruction(question)if rev_ans is not None:return rev_ans# 0) YouTube special-case: count distinct bird species from descriptionm = YOUTUBE_RE.search(question)if m:
app.py+41