Spaces:
Build error
Build error
Evan Lesmez
commited on
Commit
·
11cbf92
1
Parent(s):
7386064
Annotate more images and retest
Browse files
assets/images/vegan_ingredients/annotations.json
CHANGED
|
@@ -3,9 +3,9 @@
|
|
| 3 |
{
|
| 4 |
"file_name": "fridge-splendid.jpg",
|
| 5 |
"ingredients": [
|
| 6 |
-
"
|
| 7 |
"brown rice taco bowl",
|
| 8 |
-
"
|
| 9 |
"asparagus",
|
| 10 |
"avocado",
|
| 11 |
"nut butter"
|
|
@@ -26,7 +26,7 @@
|
|
| 26 |
"soy milk",
|
| 27 |
"bananas",
|
| 28 |
"tomatoes",
|
| 29 |
-
"
|
| 30 |
"cucumber",
|
| 31 |
"carrot"
|
| 32 |
]
|
|
@@ -35,7 +35,7 @@
|
|
| 35 |
"file_name": "veggie-fridge.jpg",
|
| 36 |
"ingredients": [
|
| 37 |
"avocado",
|
| 38 |
-
"
|
| 39 |
"cashew yogurt",
|
| 40 |
"ginger",
|
| 41 |
"lettuce"
|
|
@@ -62,6 +62,90 @@
|
|
| 62 |
"broccoli",
|
| 63 |
"kale"
|
| 64 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
]
|
| 67 |
}
|
|
|
|
| 3 |
{
|
| 4 |
"file_name": "fridge-splendid.jpg",
|
| 5 |
"ingredients": [
|
| 6 |
+
"oat milk",
|
| 7 |
"brown rice taco bowl",
|
| 8 |
+
"broccoli",
|
| 9 |
"asparagus",
|
| 10 |
"avocado",
|
| 11 |
"nut butter"
|
|
|
|
| 26 |
"soy milk",
|
| 27 |
"bananas",
|
| 28 |
"tomatoes",
|
| 29 |
+
"cereal",
|
| 30 |
"cucumber",
|
| 31 |
"carrot"
|
| 32 |
]
|
|
|
|
| 35 |
"file_name": "veggie-fridge.jpg",
|
| 36 |
"ingredients": [
|
| 37 |
"avocado",
|
| 38 |
+
"oat milk",
|
| 39 |
"cashew yogurt",
|
| 40 |
"ginger",
|
| 41 |
"lettuce"
|
|
|
|
| 62 |
"broccoli",
|
| 63 |
"kale"
|
| 64 |
]
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"file_name": "pantry/1.jpg",
|
| 68 |
+
"ingredients": [
|
| 69 |
+
"salsa",
|
| 70 |
+
"coconut milk",
|
| 71 |
+
"tomato soup",
|
| 72 |
+
"tomato paste",
|
| 73 |
+
"cashews"
|
| 74 |
+
]
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"file_name": "pantry/2.jpg",
|
| 78 |
+
"ingredients": [
|
| 79 |
+
"peanut butter",
|
| 80 |
+
"nuts"
|
| 81 |
+
]
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"file_name": "pantry/3.jpg",
|
| 85 |
+
"ingredients": [
|
| 86 |
+
"egg replacer"
|
| 87 |
+
]
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"file_name": "pantry/4.jpg",
|
| 91 |
+
"ingredients": [
|
| 92 |
+
"peanut butter",
|
| 93 |
+
"coconut milk",
|
| 94 |
+
"potatoes",
|
| 95 |
+
"sweet potatoes",
|
| 96 |
+
"muffins",
|
| 97 |
+
"chex cereal",
|
| 98 |
+
"crackers",
|
| 99 |
+
"salsa"
|
| 100 |
+
]
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"file_name": "pantry/5.jpg",
|
| 104 |
+
"ingredients": [
|
| 105 |
+
"pasta",
|
| 106 |
+
"coffee",
|
| 107 |
+
"flax seeds"
|
| 108 |
+
]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"file_name": "pantry/6.jpg",
|
| 112 |
+
"ingredients": [
|
| 113 |
+
"apple cider vinegar",
|
| 114 |
+
"pasta sauce",
|
| 115 |
+
"maple syrup",
|
| 116 |
+
"peppermint tea"
|
| 117 |
+
]
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"file_name": "pantry/7.jpg",
|
| 121 |
+
"ingredients": [
|
| 122 |
+
"almonds",
|
| 123 |
+
"wheat gluten",
|
| 124 |
+
"penne pasta",
|
| 125 |
+
"bulgur",
|
| 126 |
+
"yellow rice",
|
| 127 |
+
"pasta",
|
| 128 |
+
"walnuts",
|
| 129 |
+
"grains"
|
| 130 |
+
]
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"file_name": "pantry/8.jpg",
|
| 134 |
+
"ingredients": [
|
| 135 |
+
"rice",
|
| 136 |
+
"beans",
|
| 137 |
+
"blackeye peas"
|
| 138 |
+
]
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"file_name": "pantry/9.jpg",
|
| 142 |
+
"ingredients": [
|
| 143 |
+
"soy sauce",
|
| 144 |
+
"lemonade",
|
| 145 |
+
"blackeye peas",
|
| 146 |
+
"rice",
|
| 147 |
+
"beans"
|
| 148 |
+
]
|
| 149 |
}
|
| 150 |
]
|
| 151 |
}
|
nbs/04_gptv.ipynb
CHANGED
|
@@ -39,6 +39,7 @@
|
|
| 39 |
"import json\n",
|
| 40 |
"import logging\n",
|
| 41 |
"import os\n",
|
|
|
|
| 42 |
"import time\n",
|
| 43 |
"from glob import glob\n",
|
| 44 |
"from logging.handlers import RotatingFileHandler\n",
|
|
@@ -58,9 +59,9 @@
|
|
| 58 |
"outputs": [],
|
| 59 |
"source": [
|
| 60 |
"#| hide\n",
|
|
|
|
| 61 |
"from dotenv import load_dotenv\n",
|
| 62 |
-
"from ipywidgets import widgets
|
| 63 |
-
"import markdown"
|
| 64 |
]
|
| 65 |
},
|
| 66 |
{
|
|
@@ -584,6 +585,7 @@
|
|
| 584 |
"# function takes a prompt, tries it on all annotated images, evaluates keywords presence (lowered), ouputs data for analytics\n",
|
| 585 |
"def eval_ingredient_prompt(prompt: str):\n",
|
| 586 |
" data = []\n",
|
|
|
|
| 587 |
" for i, entry in enumerate(annotations[\"images\"]):\n",
|
| 588 |
" logging.info(f\"On image {i} of {len(annotations['images'])}\")\n",
|
| 589 |
" msg = get_gptv_completion(prompt, f\"{SAMPLE_IMG_DIR}/{entry['file_name']}\")\n",
|
|
@@ -598,9 +600,8 @@
|
|
| 598 |
"metadata": {},
|
| 599 |
"outputs": [],
|
| 600 |
"source": [
|
| 601 |
-
"
|
| 602 |
-
"
|
| 603 |
-
")"
|
| 604 |
]
|
| 605 |
},
|
| 606 |
{
|
|
@@ -638,7 +639,35 @@
|
|
| 638 |
{
|
| 639 |
"data": {
|
| 640 |
"application/vnd.jupyter.widget-view+json": {
|
| 641 |
-
"model_id": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
"version_major": 2,
|
| 643 |
"version_minor": 0
|
| 644 |
},
|
|
@@ -674,6 +703,8 @@
|
|
| 674 |
"\n",
|
| 675 |
"def display_ingredient_results(metrics_data):\n",
|
| 676 |
" vboxes = []\n",
|
|
|
|
|
|
|
| 677 |
" for d in metrics_data:\n",
|
| 678 |
" img = widgets.Image(\n",
|
| 679 |
" value=open(f\"{SAMPLE_IMG_DIR}/{d['img']}\", \"rb\").read(),\n",
|
|
@@ -692,7 +723,7 @@
|
|
| 692 |
" w_percent_ing = widgets.HTML(\n",
|
| 693 |
" value=f\"<p style='font-weight: bold;'>Ingredients found: {d['percent_ing_covered']}%</p>\"\n",
|
| 694 |
" )\n",
|
| 695 |
-
" w_completion = widgets.HTML(value=markdown.markdown(d[
|
| 696 |
" vbox = widgets.VBox(\n",
|
| 697 |
" [img, w_percent_ing] + texts + [w_completion],\n",
|
| 698 |
" layout=widgets.Layout(\n",
|
|
@@ -704,7 +735,7 @@
|
|
| 704 |
" hbox = widgets.HBox(vboxes, layout=widgets.Layout(overflow=\"scroll\"))\n",
|
| 705 |
" display(hbox)\n",
|
| 706 |
"\n",
|
| 707 |
-
"\n",
|
| 708 |
"display_ingredient_results(analyze_ingredient_results(prompt1_data))"
|
| 709 |
]
|
| 710 |
},
|
|
@@ -718,6 +749,18 @@
|
|
| 718 |
"```\n"
|
| 719 |
]
|
| 720 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 721 |
{
|
| 722 |
"cell_type": "code",
|
| 723 |
"execution_count": null,
|
|
|
|
| 39 |
"import json\n",
|
| 40 |
"import logging\n",
|
| 41 |
"import os\n",
|
| 42 |
+
"import statistics\n",
|
| 43 |
"import time\n",
|
| 44 |
"from glob import glob\n",
|
| 45 |
"from logging.handlers import RotatingFileHandler\n",
|
|
|
|
| 59 |
"outputs": [],
|
| 60 |
"source": [
|
| 61 |
"#| hide\n",
|
| 62 |
+
"import markdown\n",
|
| 63 |
"from dotenv import load_dotenv\n",
|
| 64 |
+
"from ipywidgets import widgets"
|
|
|
|
| 65 |
]
|
| 66 |
},
|
| 67 |
{
|
|
|
|
| 585 |
"# function takes a prompt, tries it on all annotated images, evaluates keywords presence (lowered), ouputs data for analytics\n",
|
| 586 |
"def eval_ingredient_prompt(prompt: str):\n",
|
| 587 |
" data = []\n",
|
| 588 |
+
" annotations = load_json(f\"{SAMPLE_IMG_DIR}/annotations.json\")\n",
|
| 589 |
" for i, entry in enumerate(annotations[\"images\"]):\n",
|
| 590 |
" logging.info(f\"On image {i} of {len(annotations['images'])}\")\n",
|
| 591 |
" msg = get_gptv_completion(prompt, f\"{SAMPLE_IMG_DIR}/{entry['file_name']}\")\n",
|
|
|
|
| 600 |
"metadata": {},
|
| 601 |
"outputs": [],
|
| 602 |
"source": [
|
| 603 |
+
"prompt1 = \"What vegan ingredients are in the image? Ouput as JSON list.\"\n",
|
| 604 |
+
"prompt1_data = eval_ingredient_prompt(prompt1)"
|
|
|
|
| 605 |
]
|
| 606 |
},
|
| 607 |
{
|
|
|
|
| 639 |
{
|
| 640 |
"data": {
|
| 641 |
"application/vnd.jupyter.widget-view+json": {
|
| 642 |
+
"model_id": "8a46c8962bae4467a0c5808f693a4aaf",
|
| 643 |
+
"version_major": 2,
|
| 644 |
+
"version_minor": 0
|
| 645 |
+
},
|
| 646 |
+
"text/plain": [
|
| 647 |
+
"HTML(value='<h3>Prompt: What vegan ingredients are in the image? Ouput as JSON list.</h3>')"
|
| 648 |
+
]
|
| 649 |
+
},
|
| 650 |
+
"metadata": {},
|
| 651 |
+
"output_type": "display_data"
|
| 652 |
+
},
|
| 653 |
+
{
|
| 654 |
+
"data": {
|
| 655 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 656 |
+
"model_id": "91867d0c4167416f85ac077c33888a3b",
|
| 657 |
+
"version_major": 2,
|
| 658 |
+
"version_minor": 0
|
| 659 |
+
},
|
| 660 |
+
"text/plain": [
|
| 661 |
+
"HTML(value='<h3>Mean ingredients found: 58%</h3>')"
|
| 662 |
+
]
|
| 663 |
+
},
|
| 664 |
+
"metadata": {},
|
| 665 |
+
"output_type": "display_data"
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"data": {
|
| 669 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 670 |
+
"model_id": "f85834f8d12e4f9e8e73cc496bf41e12",
|
| 671 |
"version_major": 2,
|
| 672 |
"version_minor": 0
|
| 673 |
},
|
|
|
|
| 703 |
"\n",
|
| 704 |
"def display_ingredient_results(metrics_data):\n",
|
| 705 |
" vboxes = []\n",
|
| 706 |
+
" mean_ing_covered_p = round(statistics.mean([d['percent_ing_covered'] for d in metrics_data]))\n",
|
| 707 |
+
" display(widgets.HTML(value=f\"<h3>Mean ingredients found: {mean_ing_covered_p}%</h3>\"))\n",
|
| 708 |
" for d in metrics_data:\n",
|
| 709 |
" img = widgets.Image(\n",
|
| 710 |
" value=open(f\"{SAMPLE_IMG_DIR}/{d['img']}\", \"rb\").read(),\n",
|
|
|
|
| 723 |
" w_percent_ing = widgets.HTML(\n",
|
| 724 |
" value=f\"<p style='font-weight: bold;'>Ingredients found: {d['percent_ing_covered']}%</p>\"\n",
|
| 725 |
" )\n",
|
| 726 |
+
" w_completion = widgets.HTML(value=markdown.markdown(d[\"gptv_completion\"]))\n",
|
| 727 |
" vbox = widgets.VBox(\n",
|
| 728 |
" [img, w_percent_ing] + texts + [w_completion],\n",
|
| 729 |
" layout=widgets.Layout(\n",
|
|
|
|
| 735 |
" hbox = widgets.HBox(vboxes, layout=widgets.Layout(overflow=\"scroll\"))\n",
|
| 736 |
" display(hbox)\n",
|
| 737 |
"\n",
|
| 738 |
+
"display(widgets.HTML(value=f\"<h3>Prompt: {prompt1}</h3>\"))\n",
|
| 739 |
"display_ingredient_results(analyze_ingredient_results(prompt1_data))"
|
| 740 |
]
|
| 741 |
},
|
|
|
|
| 749 |
"```\n"
|
| 750 |
]
|
| 751 |
},
|
| 752 |
+
{
|
| 753 |
+
"cell_type": "markdown",
|
| 754 |
+
"metadata": {},
|
| 755 |
+
"source": [
|
| 756 |
+
"Normalize .jpg file ending\n",
|
| 757 |
+
"```sh\n",
|
| 758 |
+
"for file in *.JPG; do\n",
|
| 759 |
+
" mv \"$file\" \"${file%.JPG}.jpg\"\n",
|
| 760 |
+
"done\n",
|
| 761 |
+
"```"
|
| 762 |
+
]
|
| 763 |
+
},
|
| 764 |
{
|
| 765 |
"cell_type": "code",
|
| 766 |
"execution_count": null,
|