daniescamilla commited on
Commit
df9e06e
verified
1 Parent(s): 0d58129

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -64,33 +64,34 @@ def translate_recipe(recipe):
64
  translated_recipe = translator(recipe)[0]['translation_text']
65
  return translated_recipe
66
 
67
- # Paso 4: Crear la interfaz de Gradio
68
- iface = gr.Interface(
69
- fn=process_image,
70
- inputs=gr.Image(type="pil"),
71
- outputs=[gr.Textbox(label="Dish"), gr.Textbox(label="Recipe")],
72
- title="Recipe Generator from Dish Image",
73
- description="Upload an image of a dish to get a detailed description, ingredient list, and step-by-step recipe.",
74
- flagging_mode="never"
75
- )
 
 
76
 
77
- # A帽adir bot贸n para traducir la receta
78
- def translate_interface(recipe):
79
- translated_recipe = translate_recipe(recipe)
80
- return translated_recipe
 
 
81
 
82
- iface_with_translation = gr.Interface(
83
- fn=process_image,
84
- inputs=gr.Image(type="pil"),
85
- outputs=[
86
- gr.Textbox(label="Dish"),
87
- gr.Textbox(label="Recipe"),
88
- gr.Button("Translate Recipe to Spanish").click(fn=translate_interface, inputs="Recipe", outputs=gr.Textbox(label="Translated Recipe"))
89
- ],
90
- title="Recipe Generator from Dish Image",
91
- description="Upload an image of a dish to get a detailed description, ingredient list, and step-by-step recipe. Optionally, translate the recipe to Spanish.",
92
- flagging_mode="never"
93
- )
94
 
95
  # Lanzar la aplicaci贸n de Gradio
 
96
  iface_with_translation.launch()
 
64
  translated_recipe = translator(recipe)[0]['translation_text']
65
  return translated_recipe
66
 
67
+ # Paso 4: Crear la interfaz de Gradio con bloques
68
+ def create_interface():
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
+ iface_with_translation = create_interface()
97
  iface_with_translation.launch()