Spaces:
Sleeping
Sleeping
Update app.py
Browse files41 unmodified lines424344454645464748494748495051525354555657585960616263646566675253545568697071727374755758597677787980818264656683848586878841 unmodified lines if 'how many' in original_question.lower(): # Look for numbers in the response
if 'album' in original_question.lower(): # Look for patterns specifically related to album counts album_patterns = [ r'(\d+)\s+album', r'(\d+)\s+studio\s+album', r'is\s+(\d+)', r'are\s+(\d+)' album_patterns = [ r'(\d+)\s+studio albums?', r'(\d+)\s+albums?', r'is\s+(\d+)\s+studio albums?', r'are\s+(\d+)\s+studio albums?', r'count\s+is\s+(\d+)', r'total\s+of\s+(\d+)\s+studio albums?', r'released\s+(\d+)\s+studio albums?', ] for pattern in album_patterns: match = re.search(pattern, cleaned, re.IGNORECASE) if match: return match.group(1) # General "how many" patterns general_patterns = [ r'(?:is|are)\s*(\d+)', r'^\s*(\d+)', ] for pattern in album_patterns: match = re.search(pattern, cleaned, re.IGNORECASE) if match: return match.group(1) for pattern in general_patterns: numbers = re.findall(pattern, cleaned) if numbers: # For album counts, we expect a small number (typically less than 20) for num in numbers: if int(num) < 20: return num # If no specific album pattern found, look for any number that makes sense as a count numbers = re.findall(r'\d+', cleaned) for num in numbers: # Last resort: look for any small number in the response all_numbers = re.findall(r'\d+', cleaned) for num in all_numbers: # Album counts are typically small numbers if int(num) < 20: return num # Last resort: return the first number found if numbers: return numbers[0] # Final fallback: return the first number found if all_numbers: return all_numbers[0] # If it's asking for a year, try to extract just the year if re.search(r'\b(19|20)\d{2}\b', original_question):app.py+34-15