rasyidf commited on
Commit
ea88eb3
·
1 Parent(s): f267273

Update Meatball

Browse files
Files changed (2) hide show
  1. .streamlit/config.toml +4 -0
  2. app.py +30 -4
.streamlit/config.toml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ [theme]
2
+ base="light"
3
+ primaryColor="#1f8ad2"
4
+ secondaryBackgroundColor="#b9cdf7"
app.py CHANGED
@@ -13,10 +13,34 @@ default_param_ranges = {
13
  'baking_powder': (0.25, 0.75)
14
  }
15
 
 
 
 
 
 
 
 
 
 
 
 
16
  def generate_recipe(param_ranges):
17
  return {k: random.uniform(v[0], v[1]) for k, v in param_ranges.items()}
18
 
19
  def simulate_mixing(recipe, mix_factor):
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  return mix_factor
21
 
22
  def evaluate_squishiness(recipe):
@@ -79,12 +103,14 @@ def mutate(recipe, mutation_rate, param_ranges):
79
  return recipe
80
 
81
  # Streamlit app
82
- st.title('Meatball Recipe Simulator')
83
 
84
  # Custom parameter ranges
85
  st.sidebar.header('Custom Parameter Ranges')
86
  param_ranges = {}
87
  for param, (low, high) in default_param_ranges.items():
 
 
88
  low_val = st.sidebar.number_input(f'{param.capitalize()} Min', value=low, key=f'{param}_min')
89
  high_val = st.sidebar.number_input(f'{param.capitalize()} Max', value=high, key=f'{param}_max')
90
  param_ranges[param] = (low_val, high_val)
@@ -104,16 +130,16 @@ taste_weights = {
104
  'garlic': st.sidebar.slider('Weight for Garlic', 0.0, 1.0, 0.3),
105
  'cilantro': st.sidebar.slider('Weight for Cilantro', 0.0, 1.0, 0.2)
106
  }
107
- mix_factor = st.sidebar.slider('Mix Factor', 0.0, 1.0, 0.1)
108
 
109
- st.sidebar.header('Genetic Algorithm')
110
  # Other parameters
111
  pop_size = st.sidebar.slider('Population Size', 50, 200, 100)
112
  generations = st.sidebar.slider('Generations', 10, 100, 50)
113
  mutation_rate = st.sidebar.slider('Mutation Rate', 0.01, 0.2, 0.1)
 
114
 
115
  if st.button('Run Simulation'):
116
- best_recipe = genetic_algorithm(param_ranges, weights, pop_size, generations, mutation_rate, mix_factor, taste_weights)
 
117
  st.subheader('Best Recipe')
118
  for ingredient, amount in best_recipe.items():
119
  st.write(f'{ingredient.capitalize()}: {amount:.2f}')
 
13
  'baking_powder': (0.25, 0.75)
14
  }
15
 
16
+ # Explanations for each parameter
17
+ param_explanations = {
18
+ 'beef': 'Amount of beef in grams.',
19
+ 'cornflour': 'Amount of cornflour in grams.',
20
+ 'garlic': 'Number of garlic cloves.',
21
+ 'cilantro': 'Amount of cilantro in grams.',
22
+ 'salt': 'Amount of salt in teaspoons.',
23
+ 'pepper': 'Amount of pepper in teaspoons.',
24
+ 'baking_powder': 'Amount of baking powder in teaspoons.'
25
+ }
26
+
27
  def generate_recipe(param_ranges):
28
  return {k: random.uniform(v[0], v[1]) for k, v in param_ranges.items()}
29
 
30
  def simulate_mixing(recipe, mix_factor):
31
+ beef = recipe['beef']
32
+ cornflour = recipe['cornflour']
33
+ # Simulate mixing by dividing beef by cornflour and adding mix factor
34
+
35
+ # If cornflour is 0, return 0
36
+ if cornflour == 0:
37
+ return 0
38
+ mix_factor = (beef / cornflour) + mix_factor
39
+
40
+ # If mix factor is greater than 1, return 1
41
+ if mix_factor > 1:
42
+ return 1
43
+
44
  return mix_factor
45
 
46
  def evaluate_squishiness(recipe):
 
103
  return recipe
104
 
105
  # Streamlit app
106
+ st.title('🧆 Meatball Recipe Simulator')
107
 
108
  # Custom parameter ranges
109
  st.sidebar.header('Custom Parameter Ranges')
110
  param_ranges = {}
111
  for param, (low, high) in default_param_ranges.items():
112
+ st.sidebar.markdown(f'**{param.capitalize()}**')
113
+ st.sidebar.write(param_explanations[param])
114
  low_val = st.sidebar.number_input(f'{param.capitalize()} Min', value=low, key=f'{param}_min')
115
  high_val = st.sidebar.number_input(f'{param.capitalize()} Max', value=high, key=f'{param}_max')
116
  param_ranges[param] = (low_val, high_val)
 
130
  'garlic': st.sidebar.slider('Weight for Garlic', 0.0, 1.0, 0.3),
131
  'cilantro': st.sidebar.slider('Weight for Cilantro', 0.0, 1.0, 0.2)
132
  }
 
133
 
 
134
  # Other parameters
135
  pop_size = st.sidebar.slider('Population Size', 50, 200, 100)
136
  generations = st.sidebar.slider('Generations', 10, 100, 50)
137
  mutation_rate = st.sidebar.slider('Mutation Rate', 0.01, 0.2, 0.1)
138
+ mix_factor = st.sidebar.slider('Mix Factor', 0.0, 1.0, 0.1)
139
 
140
  if st.button('Run Simulation'):
141
+ with st.spinner('Running genetic algorithm...'):
142
+ best_recipe = genetic_algorithm(param_ranges, weights, pop_size, generations, mutation_rate, mix_factor, taste_weights)
143
  st.subheader('Best Recipe')
144
  for ingredient, amount in best_recipe.items():
145
  st.write(f'{ingredient.capitalize()}: {amount:.2f}')