-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmega_pizza_app.py
More file actions
137 lines (105 loc) · 3.61 KB
/
Copy pathmega_pizza_app.py
File metadata and controls
137 lines (105 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from time import sleep
from typing import List
import streamlit
from pizza_lib import (
PizzaCrust,
PizzaSauce,
PizzaTopping,
Pizza,
PizzaOrder,
PIZZA_SIZES,
PIZZA_CRUSTS,
PIZZA_SAUCES,
PIZZA_TOPPINGS,
)
streamlit.set_page_config(
page_title="MegaPizza",
page_icon="pizza",
layout="centered",
)
streamlit.title("MegaPizza")
streamlit.header("Number of Pizza Configurations")
NUMBER_PIZZA_CONFIGURATIONS = streamlit.number_input(
"Select Number of Pizza Configurations",
min_value=0,
max_value=10,
step=1,
value=1,
)
PIZZAS: List[Pizza] = []
if NUMBER_PIZZA_CONFIGURATIONS == 0:
streamlit.info("We can't make zero Pizzas!")
else:
streamlit.header("Configure your MegaPizza")
for pizza_id in range(1, NUMBER_PIZZA_CONFIGURATIONS + 1):
streamlit.subheader(f"Pizza #{pizza_id}")
pizza_size = streamlit.select_slider(
"Select a Pizza Size",
PIZZA_SIZES,
format_func=lambda size: f"⌀{size}cm",
key=f"pizza_size#{pizza_id}",
)
CRUST_COLUMN, SAUCE_COLUMN = streamlit.columns(2)
CRUST_PREVIEW_COLUMN, SAUCE_PREVIEW_COLUMN = streamlit.columns(2)
with CRUST_COLUMN:
pizza_crust = streamlit.radio(
"Select a Crust Type",
[crust for crust in PIZZA_CRUSTS if crust.diameter == pizza_size],
key=f"pizza_crust#{pizza_id}",
)
with CRUST_PREVIEW_COLUMN:
streamlit.image(pizza_crust.image)
with SAUCE_COLUMN:
pizza_sauce = streamlit.radio(
"Select a Sauce",
[None] + [sauce for sauce in PIZZA_SAUCES if sauce.diameter == pizza_size],
key=f"pizza_sauce#{pizza_id}",
)
with SAUCE_PREVIEW_COLUMN:
if pizza_sauce:
streamlit.image(pizza_sauce.image)
pizza_toppings = streamlit.multiselect(
"Select one or multiple Toppings",
[topping for topping in PIZZA_TOPPINGS if topping.diameter == pizza_size],
key=f"pizza_toppings#{pizza_id}",
)
if pizza_toppings:
TOPPING_COLUMNS = streamlit.columns(len(pizza_toppings))
for pizza_topping_index, pizza_topping in enumerate(pizza_toppings):
with TOPPING_COLUMNS[pizza_topping_index]:
streamlit.image(pizza_topping.image)
NAME_COLUMN, NUMBER_COLUMN = streamlit.columns(2)
with NAME_COLUMN:
pizza_name = streamlit.text_input("Pizza Name", key=f"pizza_name#{pizza_id}")
with NUMBER_COLUMN:
pizza_number = streamlit.number_input(
"How many?",
min_value=1,
max_value=12,
value=1,
step=1,
key=f"pizza_number#{pizza_id}",
)
for index in range(pizza_number):
pizza = Pizza(pizza_name, pizza_crust, pizza_sauce, *pizza_toppings)
streamlit.write(pizza)
PIZZAS.append(pizza)
streamlit.header("Make MegaPizza Order")
customer_name = streamlit.text_input("Customer Name")
customer_phone_number = streamlit.text_input("Customer Phone Number")
PIZZA_ORDER = PizzaOrder(
customer_name=customer_name,
customer_phone_number=customer_phone_number,
pizzas=PIZZAS,
)
if streamlit.button(f"Authorize Payment of {PIZZA_ORDER.price:.2f}€"):
pizza: Pizza
for pizza in PIZZA_ORDER:
streamlit.subheader(pizza.name)
pizza_progress = streamlit.progress(0)
with streamlit.spinner("Baking Pizza"):
for progress, waiting_time in enumerate(pizza.bake()):
sleep(waiting_time)
pizza_progress.progress(progress)
streamlit.image(pizza.image, caption=pizza.name)
streamlit.balloons()