Inspiration

AllergenPal was inspired by the need for a more accessible and efficient way for people with food allergies to navigate restaurant menus. A dear friend of mine has a long list of food allergies (many are uncommon) and she has a hard time enjoying herself when we go out to eat and hang out. She complained often how much of a hassle it is to confirm the food she will order will be safe for her to consume. With the increasing prevalence of food allergies and dietary restrictions, we saw an opportunity to leverage AI technology to make dining out safer and less stressful for individuals and families affected by allergies.

What it does

AllergenPal is a web application that analyzes restaurant menus for potential allergens based on user-specified allergies. Users can input a menu URL or PDF link along with their allergies, and the app processes the menu to identify and flag items that may contain those allergens. This helps users make informed decisions about their meal choices, reducing the risk of allergic reactions and enhancing their dining experience.

How we built it

We built AllergenPal using Python, leveraging several key technologies and libraries:

  1. Web scraping with BeautifulSoup for HTML menus
  2. PDF text extraction using PyPDF2
  3. Natural Language Processing with OpenAI's GPT models
  4. Local allergen keyword matching for initial filtering
  5. Pandas for data manipulation
  6. Retry mechanisms with tenacity for handling API rate limits
  7. Logging for better debugging and monitoring
  8. Caching with lru_cache to optimize performance

The application is hosted on PythonAnywhere, making it accessible to users via a web interface.

Challenges we ran into

  • Web scraping limitations: The free tier of PythonAnywhere doesn't allow web scraping, which required us to adapt our approach for menu extraction.
  • Menu formatting inconsistencies: Dealing with various menu formats, especially from web URLs, proved challenging and required flexible parsing strategies.
  • API call optimization: We faced issues with making too many OpenAI API calls when cross-referencing menu items, which led to rate limiting and increased costs.
  • PDF extraction accuracy: Fine-tuning the PDF text extraction process was necessary to improve the accuracy of menu item detection.
  • Allergen detection accuracy: Varying menu descriptions made it difficult to consistently identify all potential allergens, requiring the implementation of a comprehensive allergen keyword system.
  • Cross-referencing improvements: The system needed enhancement to identify indirect allergens in dishes, such as cheese in Oysters Rockefeller, even when not explicitly mentioned in the description.
  • Balancing efficiency and thoroughness: Finding the right balance between reducing API calls and maintaining a high level of allergen detection accuracy was an ongoing challenge.

Accomplishments that we're proud of

  • Developed a functional prototype that can process both web-based and PDF menus.
  • Implemented a hybrid approach combining local keyword matching and AI-powered analysis for allergen detection.
  • Created a user-friendly interface for inputting menus and allergies.
  • Successfully optimized the application to work within the constraints of PythonAnywhere's free tier.
  • Implemented caching and batching strategies to improve performance and reduce API calls.

What we learned

  • The importance of preprocessing and filtering data before making API calls to reduce costs and improve efficiency.
  • Techniques for handling inconsistent data formats when working with various menu styles.
  • Strategies for optimizing API usage, including caching, batching, and implementing retry mechanisms.
  • The value of combining rule-based systems (keyword matching) with AI models for more robust results.
  • The complexities involved in accurately identifying allergens in food descriptions, including the need for domain-specific knowledge.

What's next for AllergenPal

  1. Expand the allergen keyword database to cover a wider range of ingredients and their aliases.
  2. Implement a more sophisticated cross-referencing system that can infer potential allergens based on common recipes and cooking methods.
  3. Develop a custom menu parsing model to improve accuracy across various menu formats.
  4. Create a mobile app version for easier access on-the-go.
  5. Integrate with restaurant APIs or databases to automate menu updates and improve coverage.
  6. Implement user accounts to save allergen profiles and favorite restaurants.
  7. Add features for users to contribute feedback and corrections, improving the system's accuracy over time.
  8. Explore partnerships with restaurants to obtain more detailed ingredient information.
  9. Implement multi-language support to make the app accessible to a global audience.
Share this project:

Updates