Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 6 |
-
|
| 7 |
from format.format_output import format_output
|
| 8 |
from validate.validate_ingredients import validate_ingredients
|
| 9 |
from device.get_device_id import get_device_id
|
|
@@ -30,11 +28,9 @@ def generate_recipe(ingredients):
|
|
| 30 |
is_ingredients_valid = validate_ingredients(ingredients_list)
|
| 31 |
|
| 32 |
if is_ingredients_valid:
|
| 33 |
-
|
| 34 |
-
|
| 35 |
return {
|
| 36 |
-
generated_recipe: gr.Markdown(value=
|
| 37 |
-
elem_id="recipe-container", visible=True)
|
| 38 |
}
|
| 39 |
else:
|
| 40 |
error_text = "## Invalid ingredients. Please include at least 2 ingredients in a comma-separated list. e.g. brown rice, onions, garlic"
|
|
@@ -43,10 +39,40 @@ def generate_recipe(ingredients):
|
|
| 43 |
generated_recipe: gr.Markdown(value=error_text, elem_id="recipe-container", visible=True)
|
| 44 |
}
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
gr.Markdown("Start by entering a comma-separated list of ingredients below.", elem_id="header-instructions")
|
| 51 |
|
| 52 |
with gr.Column() as column:
|
|
@@ -68,9 +94,10 @@ with gr.Blocks(css="./css/styles.css") as recipegen:
|
|
| 68 |
)
|
| 69 |
|
| 70 |
generate_button.click(
|
| 71 |
-
fn=
|
| 72 |
-
inputs=[user_ingredients],
|
| 73 |
outputs=[generated_recipe]
|
| 74 |
)
|
| 75 |
|
| 76 |
recipegen.launch(share=True)
|
|
|
|
|
|
| 1 |
import json
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
|
| 5 |
from format.format_output import format_output
|
| 6 |
from validate.validate_ingredients import validate_ingredients
|
| 7 |
from device.get_device_id import get_device_id
|
|
|
|
| 28 |
is_ingredients_valid = validate_ingredients(ingredients_list)
|
| 29 |
|
| 30 |
if is_ingredients_valid:
|
| 31 |
+
# Indicate that the recipe is being generated
|
|
|
|
| 32 |
return {
|
| 33 |
+
generated_recipe: gr.Markdown(value="**Generating recipe...**", elem_id="recipe-container", visible=True)
|
|
|
|
| 34 |
}
|
| 35 |
else:
|
| 36 |
error_text = "## Invalid ingredients. Please include at least 2 ingredients in a comma-separated list. e.g. brown rice, onions, garlic"
|
|
|
|
| 39 |
generated_recipe: gr.Markdown(value=error_text, elem_id="recipe-container", visible=True)
|
| 40 |
}
|
| 41 |
|
| 42 |
+
def on_generate_click(user_input, generated_recipe):
|
| 43 |
+
# When "Generate" is clicked, generate recipe
|
| 44 |
+
generated_recipe.value = "Generating recipe..."
|
| 45 |
+
# Now call the generate_recipe function to process the input and update the result
|
| 46 |
+
result = generate_recipe(user_input)
|
| 47 |
+
generated_recipe.value = result[generated_recipe]["value"]
|
| 48 |
+
return generated_recipe
|
| 49 |
+
|
| 50 |
+
with gr.Blocks(css="""
|
| 51 |
+
#chat-container {
|
| 52 |
+
display: flex;
|
| 53 |
+
flex-direction: column;
|
| 54 |
+
height: 100vh;
|
| 55 |
+
}
|
| 56 |
+
.message {
|
| 57 |
+
padding: 10px;
|
| 58 |
+
border-radius: 5px;
|
| 59 |
+
}
|
| 60 |
+
.user-message {
|
| 61 |
+
background-color: #e6f7ff;
|
| 62 |
+
text-align: left;
|
| 63 |
+
}
|
| 64 |
+
.bot-message {
|
| 65 |
+
background-color: #f0f0f0;
|
| 66 |
+
text-align: left;
|
| 67 |
+
}
|
| 68 |
+
.gr-button {
|
| 69 |
+
background-color: #0073e6 !important;
|
| 70 |
+
color: white !important;
|
| 71 |
+
border: none !important;
|
| 72 |
+
border-radius: 5px !important;
|
| 73 |
+
}
|
| 74 |
+
""") as recipegen:
|
| 75 |
+
gr.Markdown("### An AI Model Attempting To Produce Healthier, Diabetic-Friendly Recipes", elem_id="header-sub-heading")
|
| 76 |
gr.Markdown("Start by entering a comma-separated list of ingredients below.", elem_id="header-instructions")
|
| 77 |
|
| 78 |
with gr.Column() as column:
|
|
|
|
| 94 |
)
|
| 95 |
|
| 96 |
generate_button.click(
|
| 97 |
+
fn=on_generate_click,
|
| 98 |
+
inputs=[user_ingredients, generated_recipe],
|
| 99 |
outputs=[generated_recipe]
|
| 100 |
)
|
| 101 |
|
| 102 |
recipegen.launch(share=True)
|
| 103 |
+
|