|
import gradio as gr |
|
|
|
|
|
|
|
def add_text_field(inputs): |
|
inputs.append("") |
|
return gr.update(visible=True), inputs |
|
|
|
|
|
|
|
def process_ingredients(*ingredients): |
|
return [ingredient for ingredient in ingredients if ingredient] |
|
|
|
|
|
def app(): |
|
with gr.Blocks() as demo: |
|
inputs = [] |
|
|
|
|
|
ingredient_fields = gr.Row(visible=True) |
|
|
|
|
|
with gr.Row(): |
|
add_button = gr.Button("+ Add Ingredient") |
|
submit_button = gr.Button("Submit") |
|
|
|
|
|
output = gr.Textbox(label="Ingredients List", interactive=False) |
|
|
|
|
|
def add_field(): |
|
inputs.append("") |
|
with ingredient_fields: |
|
for i, ingredient in enumerate(inputs): |
|
inputs[i] = gr.Textbox( |
|
value=inputs[i], label=f"Ingredient {i + 1}" |
|
).value |
|
|
|
|
|
def submit_list(): |
|
return process_ingredients(*inputs) |
|
|
|
|
|
add_button.click(fn=add_field) |
|
submit_button.click(fn=submit_list, outputs=output) |
|
|
|
return demo |
|
|
|
|
|
demo = app() |
|
demo.launch() |
|
|