Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 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
|
|
@@ -29,47 +31,31 @@ def generate_recipe(ingredients):
|
|
| 29 |
|
| 30 |
if is_ingredients_valid:
|
| 31 |
generated_text = perform_model_inference(ingredients_list)
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
else:
|
| 34 |
-
error_text = "## Invalid ingredients. Please include at least 2 ingredients in a comma
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
.
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
}
|
| 48 |
-
.user-message {
|
| 49 |
-
background-color: #e6f7ff;
|
| 50 |
-
text-align: left;
|
| 51 |
-
}
|
| 52 |
-
.bot-message {
|
| 53 |
-
background-color: #f0f0f0;
|
| 54 |
-
text-align: left;
|
| 55 |
-
}
|
| 56 |
-
.gr-button {
|
| 57 |
-
background-color: #0073e6 !important;
|
| 58 |
-
color: white !important;
|
| 59 |
-
border: none !important;
|
| 60 |
-
border-radius: 5px !important;
|
| 61 |
-
}
|
| 62 |
-
""") as recipegen:
|
| 63 |
-
gr.Markdown("### An AI Model Attempting To Produce Healthier, Diabetic-Friendly Recipes", elem_id="header-sub-heading")
|
| 64 |
gr.Markdown("Start by entering a comma-separated list of ingredients below.", elem_id="header-instructions")
|
| 65 |
-
|
| 66 |
with gr.Column() as column:
|
| 67 |
user_ingredients = gr.Textbox(label="Ingredients", autofocus=True, max_lines=1, elem_id="ingredients-input")
|
| 68 |
generate_button = gr.Button(value="Generate")
|
| 69 |
-
|
| 70 |
with gr.Column():
|
| 71 |
generated_recipe = gr.Markdown(visible=True)
|
| 72 |
-
|
| 73 |
examples = gr.Examples(
|
| 74 |
elem_id="examples",
|
| 75 |
examples=[
|
|
@@ -81,7 +67,6 @@ with gr.Blocks(css="""
|
|
| 81 |
inputs=[user_ingredients]
|
| 82 |
)
|
| 83 |
|
| 84 |
-
# Now we directly generate the recipe when the button is clicked
|
| 85 |
generate_button.click(
|
| 86 |
fn=generate_recipe,
|
| 87 |
inputs=[user_ingredients],
|
|
|
|
| 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
|
|
|
|
| 31 |
|
| 32 |
if is_ingredients_valid:
|
| 33 |
generated_text = perform_model_inference(ingredients_list)
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
generated_recipe: gr.Markdown(value=generated_text, label="Generated Recipe",
|
| 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"
|
| 41 |
+
|
| 42 |
+
return {
|
| 43 |
+
generated_recipe: gr.Markdown(value=error_text, elem_id="recipe-container", visible=True)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
with gr.Blocks(css="./css/styles.css") as recipegen:
|
| 48 |
+
gr.Image("./assets/dut.png", interactive=False, show_share_button=False, show_download_button=False,
|
| 49 |
+
show_fullscreen_button=False, show_label=False, elem_id="dut-logo", height=256)
|
| 50 |
+
gr.Markdown("# Recipe Generator", elem_id="header")
|
| 51 |
+
gr.Markdown("### An AI Model Attempting To Produce Healthier, Diabetic-Friendly Recipes",
|
| 52 |
+
elem_id="header-sub-heading")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
gr.Markdown("Start by entering a comma-separated list of ingredients below.", elem_id="header-instructions")
|
|
|
|
| 54 |
with gr.Column() as column:
|
| 55 |
user_ingredients = gr.Textbox(label="Ingredients", autofocus=True, max_lines=1, elem_id="ingredients-input")
|
| 56 |
generate_button = gr.Button(value="Generate")
|
|
|
|
| 57 |
with gr.Column():
|
| 58 |
generated_recipe = gr.Markdown(visible=True)
|
|
|
|
| 59 |
examples = gr.Examples(
|
| 60 |
elem_id="examples",
|
| 61 |
examples=[
|
|
|
|
| 67 |
inputs=[user_ingredients]
|
| 68 |
)
|
| 69 |
|
|
|
|
| 70 |
generate_button.click(
|
| 71 |
fn=generate_recipe,
|
| 72 |
inputs=[user_ingredients],
|