Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -57,14 +57,41 @@ def process_image(image):
|
|
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=[gr.Textbox(label="Dish"), gr.Textbox(label="Recipe")],
|
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 |
-
|
|
|
57 |
|
58 |
return description, recipe
|
59 |
|
60 |
+
# Paso 5: Funci贸n para traducir la receta si el usuario lo desea
|
61 |
+
def translate_recipe(recipe):
|
62 |
+
translator = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
|
63 |
+
translated_recipe = translator(recipe)[0]['translation_text']
|
64 |
+
return translated_recipe
|
65 |
+
|
66 |
# Paso 4: Crear la interfaz de Gradio
|
67 |
iface = gr.Interface(
|
68 |
fn=process_image,
|
69 |
inputs=gr.Image(type="pil"),
|
70 |
outputs=[gr.Textbox(label="Dish"), gr.Textbox(label="Recipe")],
|
71 |
title="Recipe Generator from Dish Image",
|
72 |
+
description="Upload an image of a dish to get a description, ingredient list, and step-by-step recipe.",
|
73 |
+
allow_flagging="never"
|
74 |
+
)
|
75 |
+
|
76 |
+
# A帽adir bot贸n para traducir la receta
|
77 |
+
translate_button = gr.Button("Translate Recipe to Spanish")
|
78 |
+
translate_output = gr.Textbox(label="Translated Recipe")
|
79 |
+
|
80 |
+
def translate_interface(recipe):
|
81 |
+
translated_recipe = translate_recipe(recipe)
|
82 |
+
return translated_recipe
|
83 |
+
|
84 |
+
translate_button.click(fn=translate_interface, inputs=iface.outputs[1], outputs=translate_output)
|
85 |
+
|
86 |
+
# Crear una interfaz con el bot贸n de traducci贸n
|
87 |
+
iface_with_translation = gr.Interface(
|
88 |
+
fn=process_image,
|
89 |
+
inputs=gr.Image(type="pil"),
|
90 |
+
outputs=[gr.Textbox(label="Dish"), gr.Textbox(label="Recipe"), translate_output],
|
91 |
+
title="Recipe Generator from Dish Image",
|
92 |
+
description="Upload an image of a dish to get a description, ingredient list, and step-by-step recipe. Optionally, translate the recipe to Spanish.",
|
93 |
+
allow_flagging="never"
|
94 |
)
|
95 |
|
96 |
# Lanzar la aplicaci贸n de Gradio
|
97 |
+
iface_with_translation.launch()
|