test app
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|
| 11 |
+
inputs.append("")
|
| 12 |
+
return gr.update(visible=True), inputs
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# Function to aggregate all inputs into a list
|
| 16 |
+
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 |
+
|
| 46 |
+
|
| 47 |
+
demo = app()
|
| 48 |
+
demo.launch()
|