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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -49,13 +49,14 @@ 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 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 5: Funci贸n para traducir la receta si el usuario lo desea
61
  def translate_recipe(recipe):
@@ -69,28 +70,26 @@ iface = gr.Interface(
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
 
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 espec铆fica del plato de comida
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 espec铆fica
57
+ recipe = generate_recipe(specific_description)
58
 
59
+ return specific_description, recipe
60
 
61
  # Paso 5: Funci贸n para traducir la receta si el usuario lo desea
62
  def translate_recipe(recipe):
 
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