lab2 / app.py
jedeland's picture
test app
c54c38e
raw
history blame
1.35 kB
import gradio as gr
"""
Meal Recommender System
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.
"""
# Function to dynamically add new text fields
def add_text_field(inputs):
inputs.append("")
return gr.update(visible=True), inputs
# Function to aggregate all inputs into a list
def process_ingredients(*ingredients):
return [ingredient for ingredient in ingredients if ingredient]
# Initial setup
def app():
with gr.Blocks() as demo:
inputs = []
textboxes = []
with gr.Row():
add_button = gr.Button("+ Add Ingredient")
submit_button = gr.Button("Submit")
output = gr.Textbox(label="Ingredients List", interactive=False)
# Function to update interface with new fields
def update_inputs():
textboxes.clear()
for i, value in enumerate(inputs):
box = gr.Textbox(
label=f"Ingredient {i+1}", value=value, interactive=True, lines=1
)
textboxes.append(box)
add_button.click(add_text_field, inputs, inputs, post_update=update_inputs)
submit_button.click(process_ingredients, inputs, output)
return demo
demo = app()
demo.launch()