jedeland commited on
Commit
bee75d0
·
1 Parent(s): c54c38e
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -1,10 +1,5 @@
1
  import gradio as gr
2
 
3
- """
4
- Meal Recommender System
5
- User inputs a list of ingredients and we call the model with these ingredients, prompting it to return a list of meals that can be made with these ingredients.
6
- """
7
-
8
 
9
  # Function to dynamically add new text fields
10
  def add_text_field(inputs):
@@ -17,29 +12,37 @@ def process_ingredients(*ingredients):
17
  return [ingredient for ingredient in ingredients if ingredient]
18
 
19
 
20
- # Initial setup
21
  def app():
22
  with gr.Blocks() as demo:
23
- inputs = []
24
- textboxes = []
 
 
25
 
 
26
  with gr.Row():
27
  add_button = gr.Button("+ Add Ingredient")
28
  submit_button = gr.Button("Submit")
29
 
 
30
  output = gr.Textbox(label="Ingredients List", interactive=False)
31
 
32
- # Function to update interface with new fields
33
- def update_inputs():
34
- textboxes.clear()
35
- for i, value in enumerate(inputs):
36
- box = gr.Textbox(
37
- label=f"Ingredient {i+1}", value=value, interactive=True, lines=1
38
- )
39
- textboxes.append(box)
40
-
41
- add_button.click(add_text_field, inputs, inputs, post_update=update_inputs)
42
- submit_button.click(process_ingredients, inputs, output)
 
 
 
 
 
43
 
44
  return demo
45
 
 
1
  import gradio as gr
2
 
 
 
 
 
 
3
 
4
  # Function to dynamically add new text fields
5
  def add_text_field(inputs):
 
12
  return [ingredient for ingredient in ingredients if ingredient]
13
 
14
 
 
15
  def app():
16
  with gr.Blocks() as demo:
17
+ inputs = [] # Shared list to store ingredients
18
+
19
+ # Container to hold text fields
20
+ ingredient_fields = gr.Row(visible=True)
21
 
22
+ # Buttons for adding and submitting
23
  with gr.Row():
24
  add_button = gr.Button("+ Add Ingredient")
25
  submit_button = gr.Button("Submit")
26
 
27
+ # Output field for displaying the list
28
  output = gr.Textbox(label="Ingredients List", interactive=False)
29
 
30
+ # Function to add a new ingredient field
31
+ def add_field():
32
+ inputs.append("") # Add a new placeholder for the new input
33
+ with ingredient_fields:
34
+ for i, ingredient in enumerate(inputs):
35
+ inputs[i] = gr.Textbox(
36
+ value=inputs[i], label=f"Ingredient {i + 1}"
37
+ ).value
38
+
39
+ # Function to submit
40
+ def submit_list():
41
+ return process_ingredients(*inputs)
42
+
43
+ # Click logic for the buttons
44
+ add_button.click(fn=add_field)
45
+ submit_button.click(fn=submit_list, outputs=output)
46
 
47
  return demo
48