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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -40
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 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):
63
- translator = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
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()
 
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()