Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,49 +49,22 @@ def generate_recipe(description):
|
|
49 |
|
50 |
# Paso 3: Define la funci贸n principal para procesar la imagen y generar la receta
|
51 |
def process_image(image):
|
52 |
-
# Paso 3.1: Generar descripci贸n
|
53 |
description = image_to_text(image)[0]['generated_text']
|
54 |
-
specific_description = f"The dish appears to contain the following elements: {description}. Please describe in detail the ingredients and their arrangement."
|
55 |
|
56 |
-
# Paso 3.2: Generar receta a partir de la descripci贸n
|
57 |
-
recipe = generate_recipe(
|
58 |
|
59 |
-
return
|
60 |
|
61 |
-
# Paso
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
with gr.Blocks() as iface:
|
70 |
-
with gr.Row():
|
71 |
-
image_input = gr.Image(type="pil", label="Upload Dish Image")
|
72 |
-
with gr.Row():
|
73 |
-
description_output = gr.Textbox(label="Dish Description")
|
74 |
-
recipe_output = gr.Textbox(label="Recipe")
|
75 |
-
with gr.Row():
|
76 |
-
translate_button = gr.Button("Translate Recipe to Spanish")
|
77 |
-
translated_output = gr.Textbox(label="Translated Recipe")
|
78 |
-
|
79 |
-
# Procesar imagen y generar receta
|
80 |
-
def process_and_translate(image):
|
81 |
-
description, recipe = process_image(image)
|
82 |
-
return description, recipe, ""
|
83 |
-
|
84 |
-
image_input.change(fn=process_and_translate, inputs=image_input, outputs=[description_output, recipe_output, translated_output])
|
85 |
-
|
86 |
-
# Traducir receta
|
87 |
-
def translate_interface(recipe):
|
88 |
-
translated_recipe = translate_recipe(recipe)
|
89 |
-
return translated_recipe
|
90 |
-
|
91 |
-
translate_button.click(fn=translate_interface, inputs=recipe_output, outputs=translated_output)
|
92 |
-
|
93 |
-
return iface
|
94 |
|
95 |
# Lanzar la aplicaci贸n de Gradio
|
96 |
-
|
97 |
-
iface_with_translation.launch()
|
|
|
49 |
|
50 |
# Paso 3: Define la funci贸n principal para procesar la imagen y generar la receta
|
51 |
def process_image(image):
|
52 |
+
# Paso 3.1: Generar descripci贸n del plato
|
53 |
description = image_to_text(image)[0]['generated_text']
|
|
|
54 |
|
55 |
+
# Paso 3.2: Generar receta a partir de la descripci贸n
|
56 |
+
recipe = generate_recipe(description)
|
57 |
|
58 |
+
return description, recipe
|
59 |
|
60 |
+
# Paso 4: Crear la interfaz de Gradio
|
61 |
+
iface = gr.Interface(
|
62 |
+
fn=process_image,
|
63 |
+
inputs=gr.Image(type="pil"),
|
64 |
+
outputs=["text", "text"],
|
65 |
+
title="Recipe Generator from Dish Image",
|
66 |
+
description="Upload an image of a dish to get a description, ingredient list, and step-by-step recipe."
|
67 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# Lanzar la aplicaci贸n de Gradio
|
70 |
+
iface.launch()
|
|