Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,16 +33,21 @@ def generate_recipe(ingredients):
|
|
| 33 |
return {
|
| 34 |
generated_recipe: gr.Markdown(value=generated_text, label="Generated Recipe",
|
| 35 |
elem_id="recipe-container", visible=True),
|
| 36 |
-
|
| 37 |
}
|
| 38 |
else:
|
| 39 |
error_text = "## Invalid ingredients. Please include at least 2 ingredients in a comma-separated list. e.g. brown rice, onions, garlic"
|
| 40 |
|
| 41 |
return {
|
| 42 |
generated_recipe: gr.Markdown(value=error_text, elem_id="recipe-container", visible=True),
|
| 43 |
-
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
with gr.Blocks(css="""
|
| 48 |
#chat-container {
|
|
@@ -101,7 +106,7 @@ with gr.Blocks(css="""
|
|
| 101 |
user_input = gr.Textbox(label="Enter Ingredients (comma-separated)", placeholder="e.g. chicken, onions, garlic", autofocus=True, max_lines=1, elem_id="ingredients-input")
|
| 102 |
generate_button = gr.Button(value="Generate Recipe")
|
| 103 |
clear_button = gr.Button(value="Clear") # Clear button to reset the chat
|
| 104 |
-
|
| 105 |
|
| 106 |
examples = gr.Examples(
|
| 107 |
elem_id="examples",
|
|
@@ -114,30 +119,25 @@ with gr.Blocks(css="""
|
|
| 114 |
inputs=[user_input]
|
| 115 |
)
|
| 116 |
|
| 117 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
generate_button.click(
|
| 119 |
fn=generate_recipe,
|
| 120 |
inputs=[user_input],
|
| 121 |
-
outputs=[chatbot,
|
| 122 |
)
|
| 123 |
|
| 124 |
-
# Show loading spinner while processing
|
| 125 |
-
def show_loading_spinner():
|
| 126 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 127 |
-
|
| 128 |
-
# Hide loading spinner once result is available
|
| 129 |
-
def hide_loading_spinner():
|
| 130 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 131 |
-
|
| 132 |
-
# Set actions for the loading spinner
|
| 133 |
-
generate_button.click(fn=show_loading_spinner, outputs=[loading_spinner])
|
| 134 |
-
generate_button.click(fn=hide_loading_spinner, inputs=[chatbot], outputs=[loading_spinner])
|
| 135 |
-
|
| 136 |
# Clear inputs and outputs when the "Clear" button is clicked
|
| 137 |
def clear_all():
|
| 138 |
return gr.update(value=""), gr.update(value=""), gr.update(value="", visible=False) # Clear input, output, and hide spinner
|
| 139 |
|
| 140 |
-
clear_button.click(fn=clear_all, outputs=[user_input, chatbot,
|
| 141 |
|
| 142 |
recipegen.launch(share=True)
|
| 143 |
|
|
|
|
|
|
| 33 |
return {
|
| 34 |
generated_recipe: gr.Markdown(value=generated_text, label="Generated Recipe",
|
| 35 |
elem_id="recipe-container", visible=True),
|
| 36 |
+
loading_message: gr.Markdown(value="", visible=False) # Hide loading message
|
| 37 |
}
|
| 38 |
else:
|
| 39 |
error_text = "## Invalid ingredients. Please include at least 2 ingredients in a comma-separated list. e.g. brown rice, onions, garlic"
|
| 40 |
|
| 41 |
return {
|
| 42 |
generated_recipe: gr.Markdown(value=error_text, elem_id="recipe-container", visible=True),
|
| 43 |
+
loading_message: gr.Markdown(value="", visible=False) # Hide loading message
|
| 44 |
}
|
| 45 |
|
| 46 |
+
def show_loading_message():
|
| 47 |
+
return gr.Markdown(value="Processing... Please wait.", visible=True)
|
| 48 |
+
|
| 49 |
+
def hide_loading_message():
|
| 50 |
+
return gr.Markdown(value="", visible=False)
|
| 51 |
|
| 52 |
with gr.Blocks(css="""
|
| 53 |
#chat-container {
|
|
|
|
| 106 |
user_input = gr.Textbox(label="Enter Ingredients (comma-separated)", placeholder="e.g. chicken, onions, garlic", autofocus=True, max_lines=1, elem_id="ingredients-input")
|
| 107 |
generate_button = gr.Button(value="Generate Recipe")
|
| 108 |
clear_button = gr.Button(value="Clear") # Clear button to reset the chat
|
| 109 |
+
loading_message = gr.Markdown(value="", visible=False) # Loading message
|
| 110 |
|
| 111 |
examples = gr.Examples(
|
| 112 |
elem_id="examples",
|
|
|
|
| 119 |
inputs=[user_input]
|
| 120 |
)
|
| 121 |
|
| 122 |
+
# Show loading message when clicking generate button
|
| 123 |
+
generate_button.click(
|
| 124 |
+
fn=show_loading_message,
|
| 125 |
+
outputs=[loading_message]
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
# Hide the loading message and generate the recipe
|
| 129 |
generate_button.click(
|
| 130 |
fn=generate_recipe,
|
| 131 |
inputs=[user_input],
|
| 132 |
+
outputs=[chatbot, loading_message]
|
| 133 |
)
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
# Clear inputs and outputs when the "Clear" button is clicked
|
| 136 |
def clear_all():
|
| 137 |
return gr.update(value=""), gr.update(value=""), gr.update(value="", visible=False) # Clear input, output, and hide spinner
|
| 138 |
|
| 139 |
+
clear_button.click(fn=clear_all, outputs=[user_input, chatbot, loading_message])
|
| 140 |
|
| 141 |
recipegen.launch(share=True)
|
| 142 |
|
| 143 |
+
|