FlavorNet is an interactive reference that allows users (molecular gastronomy geeks) to discover flavor pairings based on flavor compound analysis. By modeling the relationships between flavor compounds, ingredients, ingredient prevalence, recipes and regional cuisines, users are able to discover new, possibly non-intuitive flavor combinations or ingredient substitutions. Combinatorial analysis also allows users to experiment with mapping flavor profiles within the context of a given cuisine. For example, a search for ingredient pairings with "egg" in Russian cuisine would return different ingredient combinations than a search for "egg" in Vietnamese cuisine.
Backend
Python, Flask, SQLAlchemy, SQLite
Frontend
D3.js, Javascript, Jinja, AJAX, Jquery, HTML, CSS, Bootstrap
The source data sets for the project are publicly available on YY Ahn's website. The recipe data sets were scraped from the recipe aggregator sites allrecipes.com, epicurious.com and menupan.com.
The data can be characterized as follows:
- 1,529 ingredients
- 1,106 flavor compounds (each ingredient could have anywhere from one to hundreds of flavor compounds. For example, "egg" contains 49 flavor compounds, while "black tea" has 239).
- 1,169,685 possible ingredient pairs, ex. (egg - beef, egg - pork, egg - n, etc.) from a total of 55,786 recipes
- 200,011 ingredient pairs when calculated within their respective cuisines, ex. (egg - beef, French), (egg - beef, Bangladesh), (egg - beef, Cajun/Creole), etc.
-
Make sure you have python installed (most Macs have it installed)
-
Make sure you have pip (package management) installed
sudo easy_install pip
-
Install the virtual environment tool
sudo pip install virtualenv
-
Create virtual environment inside the working directory.
virtualenv env
-
Source the environment:
source env/bin/activate
-
Download requirements:
pip install -r requirements.txt
-
Run the server:
python server.py
-
Navigate to: "http://localhost:5000" to view app
-
Then, source it.
To figure out what ingredients pair well ("well" defined by the number of flavor compounds the two ingredients share in common) I used Sqlalchemy to query a local SQLite database and limited the results to the first ten matches in descending order of most to least shared flavor commpounds.
I decided in favor of creating a relational table that tracked ingredient pairs within a given cuisine and the number of times the respective ingredient pair and cuisine appeared in all the recipes in the data set.
The itertools Python library was instrumental to track all possible discrete ingredient pair-cuisine combinations and discard duplicate permutations (i.e. "broccoli and kale in Italian cuisine" is the same as "kale and broccoli in Italian cuisine" and should not be counted separately).
Once this table was created, given an input ingredient and cuisine, users would be able to discover the most commonly combined ingredients characteristic to the cuisine. For example, a search with "lemon" and "Italian" will yield different ingredient pairs than "lemon" and "Asian".
Using the Reingold-Tilford tree visualization, users can click to explore the flavor profile generated by their search. For example, a search with "lemon" in "Italian" cuisine will yield a list that includes "artichoke" and "vanilla", which will yield very different flavor profiles as illustrated below.