m3hrdadfi commited on
Commit
c14838c
1 Parent(s): 1b377b0

Transfer from git

Browse files
Files changed (5) hide show
  1. app.py +5 -8
  2. dummy.py +1 -1
  3. requirements.txt +1 -1
  4. utils/draw.py +13 -5
  5. utils/ext.py +2 -1
app.py CHANGED
@@ -5,11 +5,8 @@ from transformers import pipeline, set_seed
5
  from transformers import AutoTokenizer
6
 
7
  from PIL import (
8
- Image,
9
  ImageFont,
10
- ImageDraw
11
  )
12
- import requests
13
 
14
  import os
15
  import re
@@ -124,7 +121,7 @@ class TextGeneration:
124
 
125
  def generate(self, items, generation_kwargs):
126
  recipe = self.dummy_outputs[0]
127
- recipe = self.dummy_outputs[random.randint(0, len(self.dummy_outputs) - 1)]
128
 
129
  if not self.debug:
130
  generation_kwargs["num_return_sequences"] = 1
@@ -208,7 +205,7 @@ def main():
208
  st.image(load_image_from_local("asset/images/chef-transformer-transparent.png"), width=300)
209
  st.markdown(meta.SIDEBAR_INFO, unsafe_allow_html=True)
210
 
211
- with st.beta_expander("Where did this story start?"):
212
  st.markdown(meta.STORY, unsafe_allow_html=True)
213
 
214
  with col1:
@@ -270,10 +267,10 @@ def main():
270
  generated_recipe["ingredients"],
271
  pure_comma_separation(items, return_list=True)
272
  )
 
273
 
274
- directions = [textwrap.fill(item, 70).replace("\n", "\n ") for item in
275
- generated_recipe["directions"]]
276
- directions = ext.directions(directions)
277
 
278
  generated_recipe["by"] = chef
279
 
 
5
  from transformers import AutoTokenizer
6
 
7
  from PIL import (
 
8
  ImageFont,
 
9
  )
 
10
 
11
  import os
12
  import re
 
121
 
122
  def generate(self, items, generation_kwargs):
123
  recipe = self.dummy_outputs[0]
124
+ # recipe = self.dummy_outputs[random.randint(0, len(self.dummy_outputs) - 1)]
125
 
126
  if not self.debug:
127
  generation_kwargs["num_return_sequences"] = 1
 
205
  st.image(load_image_from_local("asset/images/chef-transformer-transparent.png"), width=300)
206
  st.markdown(meta.SIDEBAR_INFO, unsafe_allow_html=True)
207
 
208
+ with st.beta_expander("Where did this story start?", expanded=True):
209
  st.markdown(meta.STORY, unsafe_allow_html=True)
210
 
211
  with col1:
 
267
  generated_recipe["ingredients"],
268
  pure_comma_separation(items, return_list=True)
269
  )
270
+ # ingredients = [textwrap.fill(item, 10).replace("\n", "<br /> ") for item in ingredients]
271
 
272
+ directions = ext.directions(generated_recipe["directions"])
273
+ # directions = [textwrap.fill(item, 70).replace("\n", "<br /> ") for item in directions]
 
274
 
275
  generated_recipe["by"] = chef
276
 
dummy.py CHANGED
@@ -20,7 +20,7 @@ recipes = [
20
  "makes 12 servings.",
21
  ],
22
  'ingredients': [
23
- "1 lb. phyllo dough, thawed",
24
  "1 c. unsalted butter, melted",
25
  "2 c chopped walnuts",
26
  "1/2 tsp. cinnamon",
 
20
  "makes 12 servings.",
21
  ],
22
  'ingredients': [
23
+ "1 lb. phyllo dough, thawed 1 lb. phyllo dough, thawed",
24
  "1 c. unsalted butter, melted",
25
  "2 c chopped walnuts",
26
  "1/2 tsp. cinnamon",
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- streamlit==0.84.1
2
  transformers
3
  torch
4
  Pillow
 
1
+ streamlit
2
  transformers
3
  torch
4
  Pillow
utils/draw.py CHANGED
@@ -1,16 +1,22 @@
1
  from PIL import (
2
  Image,
3
- ImageFont,
4
  ImageDraw
5
  )
6
  import textwrap
7
- from .utils import load_image_from_url
8
- from .ext import (
9
  ingredients as ext_ingredients,
10
  directions as ext_directions
11
  )
12
 
13
 
 
 
 
 
 
 
 
14
  def generate_food_with_logo_image(bg_path, logo_path, food_url, no_food="asset/frame/no_food.png"):
15
  bg = Image.open(bg_path)
16
  width, height = bg.size
@@ -58,8 +64,8 @@ def generate_recipe_image(
58
  font=fonts["body_bold"],
59
  )
60
  ingredients = recipe_data["ingredients"]
61
- ingredients = [textwrap.fill(item, 30).replace("\n", "\n ") for item in ingredients]
62
  ingredients = ext_ingredients(ingredients, [], without_mapping=True)
 
63
 
64
  im_editable.text(
65
  (50, 520),
@@ -76,7 +82,9 @@ def generate_recipe_image(
76
  )
77
 
78
  directions = recipe_data["directions"]
79
- directions = [textwrap.fill(item, 70).replace("\n", "\n ").capitalize() for item in directions]
 
 
80
  im_editable.text(
81
  (430, 520),
82
  "\n".join([f"{i + 1}. {item}" for i, item in enumerate(directions)]).strip(),
 
1
  from PIL import (
2
  Image,
 
3
  ImageDraw
4
  )
5
  import textwrap
6
+ from utils.utils import load_image_from_url
7
+ from utils.ext import (
8
  ingredients as ext_ingredients,
9
  directions as ext_directions
10
  )
11
 
12
 
13
+ # from .utils import load_image_from_url
14
+ # from .ext import (
15
+ # ingredients as ext_ingredients,
16
+ # directions as ext_directions
17
+ # )
18
+
19
+
20
  def generate_food_with_logo_image(bg_path, logo_path, food_url, no_food="asset/frame/no_food.png"):
21
  bg = Image.open(bg_path)
22
  width, height = bg.size
 
64
  font=fonts["body_bold"],
65
  )
66
  ingredients = recipe_data["ingredients"]
 
67
  ingredients = ext_ingredients(ingredients, [], without_mapping=True)
68
+ ingredients = [textwrap.fill(item, 30).replace("\n", "\n ") for item in ingredients]
69
 
70
  im_editable.text(
71
  (50, 520),
 
82
  )
83
 
84
  directions = recipe_data["directions"]
85
+ directions = ext_directions(directions)
86
+ directions = [textwrap.fill(item, 70).replace("\n", "\n ").capitalize() for item in directions]
87
+
88
  im_editable.text(
89
  (430, 520),
90
  "\n".join([f"{i + 1}. {item}" for i, item in enumerate(directions)]).strip(),
utils/ext.py CHANGED
@@ -1,5 +1,6 @@
1
  import re
2
- from .utils import replace_regex
 
3
 
4
  DEFAULT_MAP_DICT = {
5
  " c ": " c. ",
 
1
  import re
2
+ from utils.utils import replace_regex
3
+ # from .utils import replace_regex
4
 
5
  DEFAULT_MAP_DICT = {
6
  " c ": " c. ",