|
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. |
|
""" |
|
|
|
|
|
|
|
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 = [] |
|
textboxes = [] |
|
|
|
with gr.Row(): |
|
add_button = gr.Button("+ Add Ingredient") |
|
submit_button = gr.Button("Submit") |
|
|
|
output = gr.Textbox(label="Ingredients List", interactive=False) |
|
|
|
|
|
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() |
|
|