Spaces:
Runtime error
Runtime error
Commit
·
9dfdbcd
0
Parent(s):
initial commit
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +113 -0
- plate_comp.png +0 -0
- prompt.txt +49 -0
- requirements.txt +2 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Recipe Generation
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: purple
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.17.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: cc-by-nc-4.0
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import re
|
3 |
+
from ast import literal_eval
|
4 |
+
import openai
|
5 |
+
import plotly.graph_objects as go
|
6 |
+
|
7 |
+
api_key = st.secrets["openai_key"]
|
8 |
+
openai.api_key = api_key
|
9 |
+
st.header('Recipe Generation and Analysis')
|
10 |
+
st.markdown("Generate recipe from given ingredients and food name. Analyze the healthiness of the generated recipe. Tips: to make the recipe healthier, indicate healthiness in the food name (e.g., healthy chicken soup, very healthy fried rice, low-carb noodles)")
|
11 |
+
name = st.text_input('Food name (Optional)')
|
12 |
+
ingr = st.text_input('Ingredients')
|
13 |
+
prompt = open('prompt.txt', 'r').read()
|
14 |
+
|
15 |
+
if st.button('Generate'):
|
16 |
+
|
17 |
+
prompt = prompt.replace('[FOOD_NAME]', name).replace('[INGREDIENTS]', ingr)
|
18 |
+
max_token = 3500 - len(prompt)//4
|
19 |
+
with st.spinner('Please wait for completion'):
|
20 |
+
response = openai.Completion.create(model="text-davinci-003", prompt=prompt, temperature=0, max_tokens=max_token)
|
21 |
+
response = response['choices'][0]['text']
|
22 |
+
# response = '''Ingredients: ['1 lb ground beef', '1 onion, diced', '2 cloves garlic, minced', '1 red bell pepper, diced', '1 green bell pepper, diced', '1 jalapeño, diced', '1/2 cup tomato sauce', '1/4 cup Worcestershire sauce', '1/4 cup soy sauce', '1/4 cup brown sugar', '1/4 cup red wine vinegar', '1/4 cup olive oil', 'Salt and pepper, to taste']
|
23 |
+
# Instructions: ['In a large skillet over medium-high heat, cook the ground beef until browned. Drain off any excess fat.', 'Add the onion, garlic, bell peppers, and jalapeño to the skillet and cook until softened, about 5 minutes.', 'Stir in the tomato sauce, Worcestershire sauce, soy sauce, brown sugar, red wine vinegar, and olive oil. Season with salt and pepper, to taste.', 'Reduce heat to low and simmer for 10 minutes, stirring occasionally.', 'Serve over cooked rice or noodles.']
|
24 |
+
# Image of final dish: ['The final dish is a savory and flavorful beef stir-fry. The beef is cooked with onions, garlic, bell peppers, and jalapeño, and then simmered in a mixture of tomato sauce, Worcestershire sauce, soy sauce, brown sugar, red wine vinegar, and olive oil. The stir-fry is served over cooked rice or noodles.']
|
25 |
+
# Estimated calories in number: [500, 600]
|
26 |
+
# Healthiness score out of ten: [7]
|
27 |
+
# Estimated percentage of food categories: {'Vegetables': 40, 'Whole grains': 0, 'Healthy protein': 30, 'Fruits': 0, 'Healthy oils': 10}
|
28 |
+
# '''
|
29 |
+
print(response)
|
30 |
+
full_ingredients = literal_eval(re.findall('Ingredients: (\[.+\])', response)[0])
|
31 |
+
full_ingredients = '\n• ' + '\n• '.join(full_ingredients)
|
32 |
+
|
33 |
+
instructions = literal_eval(re.findall('Instructions: (\[.+\])', response)[0])
|
34 |
+
instructions = ['\n{}. {}'.format(str(i + 1), x) for i, x in enumerate(instructions)]
|
35 |
+
instructions = ''.join(instructions)
|
36 |
+
|
37 |
+
if name != '':
|
38 |
+
name += '. '
|
39 |
+
description = name + re.findall('Image of final dish: \[(.+)\]', response)[0]
|
40 |
+
|
41 |
+
est_cal = literal_eval(re.findall('Estimated calories in number: (\[.+\])', response)[0])
|
42 |
+
est_cal = list(map(int, est_cal))
|
43 |
+
compo = literal_eval(re.findall('Estimated percentage of food categories: ({.+})', response)[0])
|
44 |
+
if len(est_cal) == 1:
|
45 |
+
est_cal = est_cal[0]
|
46 |
+
elif len(est_cal) == 2:
|
47 |
+
est_cal = sum(est_cal) // 2
|
48 |
+
else:
|
49 |
+
print("Wrong calories output")
|
50 |
+
est_cal = est_cal[0]
|
51 |
+
healthiness = literal_eval(re.findall('Healthiness score out of ten: (\[.+\])', response)[0])
|
52 |
+
try:
|
53 |
+
healthiness = healthiness[0]
|
54 |
+
except:
|
55 |
+
print("Wrong healthiness estimation")
|
56 |
+
image_url = openai.Image.create(prompt=description, n=1, size="1024x1024")['data'][0]['url']
|
57 |
+
col1, col2 = st.columns(2)
|
58 |
+
|
59 |
+
with col1:
|
60 |
+
st.subheader('Ingredients')
|
61 |
+
st.text(full_ingredients)
|
62 |
+
|
63 |
+
with col2:
|
64 |
+
st.image(image_url, caption="Illustration of the final dish")
|
65 |
+
|
66 |
+
st.subheader('Instructions')
|
67 |
+
st.markdown(instructions)
|
68 |
+
|
69 |
+
|
70 |
+
st.subheader("Plate Analysis")
|
71 |
+
compo = {i: compo[i] for i in compo if compo[i] != 0}
|
72 |
+
labels = list(compo.keys())
|
73 |
+
values = list(map(int, list(compo.values())))
|
74 |
+
if sum(values) != 100:
|
75 |
+
labels.append('Others')
|
76 |
+
values.append(100 - sum(values))
|
77 |
+
|
78 |
+
col3, col4 = st.columns(2)
|
79 |
+
|
80 |
+
with col3:
|
81 |
+
col3.markdown(
|
82 |
+
"""
|
83 |
+
Estimated calories
|
84 |
+
<h1>🔥 {}</h1>
|
85 |
+
""".format(str(est_cal)), unsafe_allow_html=True
|
86 |
+
)
|
87 |
+
with col4:
|
88 |
+
col4.markdown(
|
89 |
+
"""
|
90 |
+
Healthiness scale
|
91 |
+
<h1>🌿 {}/10</h1>
|
92 |
+
""".format(str(healthiness)), unsafe_allow_html=True
|
93 |
+
)
|
94 |
+
st.subheader("")
|
95 |
+
st.subheader("")
|
96 |
+
col1, col2 = st.columns(2)
|
97 |
+
with col1:
|
98 |
+
col1.markdown(
|
99 |
+
"""
|
100 |
+
Plate composition
|
101 |
+
""", unsafe_allow_html=True
|
102 |
+
)
|
103 |
+
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
|
104 |
+
st.plotly_chart(fig, use_container_width=True)
|
105 |
+
|
106 |
+
with col2:
|
107 |
+
col2.markdown(
|
108 |
+
"""
|
109 |
+
Recommended composition
|
110 |
+
""", unsafe_allow_html=True
|
111 |
+
)
|
112 |
+
st.header("")
|
113 |
+
st.image('plate_comp.png')
|
plate_comp.png
ADDED
![]() |
prompt.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Given the command:
|
2 |
+
Create a full Vietnamese banh mi recipe from the following ingredients: pork belly, carrot, pate, eggs. Based on the ingredients and instructions of the generated recipe, do the following tasks:
|
3 |
+
- describe the image of the final dish
|
4 |
+
- estimate the calories (give number, no explanation)
|
5 |
+
- Estimate healthiness score in scale 0 to 10 (give number, no explanation)
|
6 |
+
- Estimate average percentage of vegetables, whole grains, healthy protein, fruits, and healthy oils in the final dish (give number, no explanation).
|
7 |
+
The corresponding answer is:
|
8 |
+
Ingredients:
|
9 |
+
• 1 baguette
|
10 |
+
• 1/2 lb pork belly, sliced
|
11 |
+
• 1 cup grated carrots
|
12 |
+
• 1/2 cup pate
|
13 |
+
• 2 eggs
|
14 |
+
• 2 tbsp soy sauce
|
15 |
+
• 2 tbsp fish sauce
|
16 |
+
• 2 tbsp sugar
|
17 |
+
• 2 tbsp vinegar
|
18 |
+
• 1/4 cup mayonnaise
|
19 |
+
• 1/4 cup sliced jalapeños
|
20 |
+
• Cilantro leaves, for garnish
|
21 |
+
Instructions:
|
22 |
+
1. In a bowl, mix together the soy sauce, fish sauce, sugar, and vinegar. Add the sliced pork belly and let marinate for at least 30 minutes.
|
23 |
+
2. Heat a pan over medium-high heat and cook the marinated pork belly until golden brown and crispy, about 5-7 minutes on each side.
|
24 |
+
3. In another pan, scramble the eggs until fully cooked.
|
25 |
+
4. Cut the baguette in half and spread mayonnaise on both sides. Layer on the cooked pork belly, scrambled eggs, grated carrots, sliced jalapeños, and cilantro leaves.
|
26 |
+
5. Spread pate on top of the other half of the baguette and place on top of the sandwich.
|
27 |
+
6. Serve immediately.
|
28 |
+
Image of final dish: The Vietnamese Banh Mi is a sandwich that is typically served on a crispy and crusty baguette. The sandwich is filled with layers of sliced pork belly, scrambled eggs, grated carrots, sliced jalapeños, and cilantro leaves. The pate is spread on the top of the sandwich, giving it a rich and savoury flavour.
|
29 |
+
Estimated calories: Approximately 650-700 calories per sandwich.
|
30 |
+
Healthiness score: 5 out of 10. While the sandwich contains some vegetables, protein, and healthy oils, it is also high in calories and fat due to the pork belly and pate.
|
31 |
+
Estimated percentage of food categories:
|
32 |
+
Vegetables: 20%
|
33 |
+
Whole grains: 20%
|
34 |
+
Healthy protein: 30%
|
35 |
+
Fruits: 0%
|
36 |
+
Healthy oils: 5% (mayonnaise)
|
37 |
+
The standardized form of the above answer is:
|
38 |
+
Ingredients: ['1 baguette', '1/2 lb pork belly, sliced', '1 cup grated carrots', '1/2 cup pate', '2 eggs', '2 tbsp soy sauce', '2 tbsp fish sauce', '2 tbsp sugar', '2 tbsp vinegar', '1/4 cup mayonnaise', '1/4 cup sliced jalapeños', 'Cilantro leaves, for garnish']
|
39 |
+
Instructions: ['In a bowl, mix together the soy sauce, fish sauce, sugar, and vinegar. Add the sliced pork belly and let marinate for at least 30 minutes.', 'Heat a pan over medium-high heat and cook the marinated pork belly until golden brown and crispy, about 5-7 minutes on each side.', 'In another pan, scramble the eggs until fully cooked.', 'Cut the baguette in half and spread mayonnaise on both sides. Layer on the cooked pork belly, scrambled eggs, grated carrots, sliced jalapeños, and cilantro leaves.', 'Spread pate on top of the other half of the baguette and place on top of the sandwich.', 'Serve immediately.']
|
40 |
+
Image of final dish: ['The Vietnamese Banh Mi is a sandwich that is typically served on a crispy and crusty baguette. The sandwich is filled with layers of sliced pork belly, scrambled eggs, grated carrots, sliced jalapeños, and cilantro leaves. The pate is spread on the top of the sandwich, giving it a rich and savory flavor.']
|
41 |
+
Estimated calories in number: [650, 700]
|
42 |
+
Healthiness score out of ten: [5]
|
43 |
+
Estimated percentage of food categories: {'Vegetables': 20, 'Whole grains': 20, 'Healthy protein': 30, 'Fruits': 0, 'Healthy oils': 5}
|
44 |
+
Now, create a [FOOD_NAME] recipe from the following ingredients: [INGREDIENTS]. Based on the ingredients and instructions of the generated recipe, do the following tasks:
|
45 |
+
- describe the image of the final dish
|
46 |
+
- estimate the calories (give number, no explanation)
|
47 |
+
- Estimate healthiness score in scale 0 to 10 (give number, no explanation)
|
48 |
+
- Estimate average percentage of vegetables, whole grains, healthy protein, fruits, and healthy oils in the final dish (give number, no explanation).
|
49 |
+
Give only the answer in the standardized form as above.
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openai==0.27.0
|
2 |
+
plotly==5.13.1
|