Spaces:
Runtime error
Runtime error
Fix UI bugs and add examples
Browse files- app.py +41 -25
- examples.py +2 -0
app.py
CHANGED
|
@@ -30,18 +30,27 @@ np.random.seed(42)
|
|
| 30 |
|
| 31 |
class TextGeneration:
|
| 32 |
def __init__(self):
|
| 33 |
-
self.debug =
|
| 34 |
self.dummy_output = {
|
| 35 |
'directions': [
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
],
|
| 46 |
'ingredients': [
|
| 47 |
'1 potato',
|
|
@@ -129,7 +138,7 @@ class TextGeneration:
|
|
| 129 |
)
|
| 130 |
# Ingredients
|
| 131 |
im_editable.text(
|
| 132 |
-
(100,
|
| 133 |
"Ingredients",
|
| 134 |
(61, 61, 70),
|
| 135 |
font=self.fonts["body_bold"],
|
|
@@ -138,33 +147,40 @@ class TextGeneration:
|
|
| 138 |
ingredients = [textwrap.fill(item, 30).replace("\n", "\n ") for item in ingredients]
|
| 139 |
|
| 140 |
im_editable.text(
|
| 141 |
-
(100,
|
| 142 |
"\n".join([f"{self.point} {item}" for item in ingredients]),
|
| 143 |
(61, 61, 70),
|
| 144 |
font=self.fonts["body"],
|
| 145 |
)
|
| 146 |
# Directions
|
| 147 |
im_editable.text(
|
| 148 |
-
(700,
|
| 149 |
"Directions",
|
| 150 |
(61, 61, 70),
|
| 151 |
font=self.fonts["body_bold"],
|
| 152 |
)
|
| 153 |
directions = recipe["directions"]
|
| 154 |
-
|
| 155 |
-
directions_col2 = [textwrap.fill(item, 30).replace("\n", "\n ") for item in directions[self.list_division:]]
|
| 156 |
im_editable.text(
|
| 157 |
-
(700,
|
| 158 |
-
"\n".join([f"{i + 1}. {item}" for i, item in enumerate(
|
| 159 |
-
(61, 61, 70),
|
| 160 |
-
font=self.fonts["body"],
|
| 161 |
-
)
|
| 162 |
-
im_editable.text(
|
| 163 |
-
(1300, 1130),
|
| 164 |
-
"\n".join([f"{i + 1 + self.list_division}. {item}" for i, item in enumerate(directions_col2)]).strip(),
|
| 165 |
(61, 61, 70),
|
| 166 |
font=self.fonts["body"],
|
| 167 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
return frame
|
| 169 |
|
| 170 |
def generate(self, items, generation_kwargs):
|
|
@@ -322,9 +338,9 @@ def main():
|
|
| 322 |
" ".join([f'<li>{item}</li>' for item in ingredients]),
|
| 323 |
"</ul>",
|
| 324 |
"<h3>Direction</h3>",
|
| 325 |
-
"<
|
| 326 |
" ".join([f'<li>{item}</li>' for item in directions]),
|
| 327 |
-
"</
|
| 328 |
"</div>"
|
| 329 |
]),
|
| 330 |
unsafe_allow_html=True
|
|
|
|
| 30 |
|
| 31 |
class TextGeneration:
|
| 32 |
def __init__(self):
|
| 33 |
+
self.debug = True
|
| 34 |
self.dummy_output = {
|
| 35 |
'directions': [
|
| 36 |
+
"for the dough",
|
| 37 |
+
"in a small bowl, combine the warm water and yeast.",
|
| 38 |
+
"let it sit for 5 minutes.",
|
| 39 |
+
"add the flour, salt, and olive oil.",
|
| 40 |
+
"mix well and knead until the dough is smooth and elastic.",
|
| 41 |
+
"cover the dough with a damp towel and let it rise for about 1 hour.",
|
| 42 |
+
"for the filling",
|
| 43 |
+
"heat a large skillet over medium high heat.",
|
| 44 |
+
"cook the beef and onion until the beef is browned and the onion is translucent. browned and the onion is translucent.",
|
| 45 |
+
"drain off any excess grease.",
|
| 46 |
+
"stir in the pepper and salt and black pepper to taste.",
|
| 47 |
+
"remove from the heat and set aside.",
|
| 48 |
+
"preheat the oven to 425 degrees f.",
|
| 49 |
+
"roll out the dough on a lightly floured surface into a 12 inch circle.",
|
| 50 |
+
"spread the beef mixture over the dough, leaving a 1 inch border.",
|
| 51 |
+
"top with the feta, parsley, and lemon juice.",
|
| 52 |
+
"bake for 20 minutes or until the crust is golden brown.",
|
| 53 |
+
"cut into wedges and serve.",
|
| 54 |
],
|
| 55 |
'ingredients': [
|
| 56 |
'1 potato',
|
|
|
|
| 138 |
)
|
| 139 |
# Ingredients
|
| 140 |
im_editable.text(
|
| 141 |
+
(100, 1000),
|
| 142 |
"Ingredients",
|
| 143 |
(61, 61, 70),
|
| 144 |
font=self.fonts["body_bold"],
|
|
|
|
| 147 |
ingredients = [textwrap.fill(item, 30).replace("\n", "\n ") for item in ingredients]
|
| 148 |
|
| 149 |
im_editable.text(
|
| 150 |
+
(100, 1080),
|
| 151 |
"\n".join([f"{self.point} {item}" for item in ingredients]),
|
| 152 |
(61, 61, 70),
|
| 153 |
font=self.fonts["body"],
|
| 154 |
)
|
| 155 |
# Directions
|
| 156 |
im_editable.text(
|
| 157 |
+
(700, 1000),
|
| 158 |
"Directions",
|
| 159 |
(61, 61, 70),
|
| 160 |
font=self.fonts["body_bold"],
|
| 161 |
)
|
| 162 |
directions = recipe["directions"]
|
| 163 |
+
directions = [textwrap.fill(item, 80).replace("\n", "\n ") for item in directions]
|
|
|
|
| 164 |
im_editable.text(
|
| 165 |
+
(700, 1080),
|
| 166 |
+
"\n".join([f"{i + 1}. {item}" for i, item in enumerate(directions)]).strip(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
(61, 61, 70),
|
| 168 |
font=self.fonts["body"],
|
| 169 |
)
|
| 170 |
+
# directions_col1 = [textwrap.fill(item, 30).replace("\n", "\n ") for item in directions[:self.list_division]]
|
| 171 |
+
# directions_col2 = [textwrap.fill(item, 30).replace("\n", "\n ") for item in directions[self.list_division:]]
|
| 172 |
+
# im_editable.text(
|
| 173 |
+
# (700, 1130),
|
| 174 |
+
# "\n".join([f"{i + 1}. {item}" for i, item in enumerate(directions_col1)]).strip(),
|
| 175 |
+
# (61, 61, 70),
|
| 176 |
+
# font=self.fonts["body"],
|
| 177 |
+
# )
|
| 178 |
+
# im_editable.text(
|
| 179 |
+
# (1300, 1130),
|
| 180 |
+
# "\n".join([f"{i + 1 + self.list_division}. {item}" for i, item in enumerate(directions_col2)]).strip(),
|
| 181 |
+
# (61, 61, 70),
|
| 182 |
+
# font=self.fonts["body"],
|
| 183 |
+
# )
|
| 184 |
return frame
|
| 185 |
|
| 186 |
def generate(self, items, generation_kwargs):
|
|
|
|
| 338 |
" ".join([f'<li>{item}</li>' for item in ingredients]),
|
| 339 |
"</ul>",
|
| 340 |
"<h3>Direction</h3>",
|
| 341 |
+
"<ol class='ingredients-list'>",
|
| 342 |
" ".join([f'<li>{item}</li>' for item in directions]),
|
| 343 |
+
"</ol>",
|
| 344 |
"</div>"
|
| 345 |
]),
|
| 346 |
unsafe_allow_html=True
|
examples.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
EXAMPLES = {
|
|
|
|
| 2 |
"Chocolate Baklava": "phyllo dough, unsalted butter, walnuts, cinnamon, water, honey, melted chocolate",
|
|
|
|
| 3 |
}
|
|
|
|
| 1 |
EXAMPLES = {
|
| 2 |
+
"Persian Chicken Stew (Fesenjan)": "walnut pieces, onion, boneless skinless chicken thighs, pomegranate molasses, orange juice, chicken stock, cinnamon, salt, pepper, oil",
|
| 3 |
"Chocolate Baklava": "phyllo dough, unsalted butter, walnuts, cinnamon, water, honey, melted chocolate",
|
| 4 |
+
"Korean Pork Chops": "pork chops, soy sauce, honey, garlic, sesame oil, fresh ginger root, sweet chili sauce, olive oil",
|
| 5 |
}
|