daniescamilla commited on
Commit
021e335
verified
1 Parent(s): 363a5a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -4,7 +4,7 @@ import requests
4
  from transformers import pipeline
5
 
6
  # Obt茅n el token desde las variables de entorno
7
- hf_token = os.getenv("HF_TOKEN") # Esta l铆nea solo debe aparecer una vez
8
 
9
  # Paso 1: Cargar el modelo de image-to-text
10
  image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
@@ -15,7 +15,7 @@ def generate_recipe(description):
15
  headers = {"Authorization": f"Bearer {hf_token}"}
16
  payload = {
17
  "inputs": f"Give me a list of ingredients and a step-by-step recipe for a dish described as: {description}",
18
- "parameters": {"max_length": 500}
19
  }
20
 
21
  response = requests.post(url, headers=headers, json=payload)
@@ -24,7 +24,9 @@ def generate_recipe(description):
24
  # Manejo de posibles errores
25
  if "error" in response_data:
26
  return "Error generating recipe: " + response_data["error"]
27
- return response_data[0]["generated_text"] if response_data else "No recipe generated."
 
 
28
 
29
  # Paso 3: Define la funci贸n principal para procesar la imagen y generar la receta
30
  def process_image(image):
 
4
  from transformers import pipeline
5
 
6
  # Obt茅n el token desde las variables de entorno
7
+ hf_token = os.getenv("HF_TOKEN")
8
 
9
  # Paso 1: Cargar el modelo de image-to-text
10
  image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
 
15
  headers = {"Authorization": f"Bearer {hf_token}"}
16
  payload = {
17
  "inputs": f"Give me a list of ingredients and a step-by-step recipe for a dish described as: {description}",
18
+ "parameters": {"max_length": 4000} # Increase max_length for a more detailed response
19
  }
20
 
21
  response = requests.post(url, headers=headers, json=payload)
 
24
  # Manejo de posibles errores
25
  if "error" in response_data:
26
  return "Error generating recipe: " + response_data["error"]
27
+
28
+ # Return only the generated text, without the input prompt
29
+ return response_data[0]["generated_text"].replace(payload["inputs"], "").strip() if response_data else "No recipe generated."
30
 
31
  # Paso 3: Define la funci贸n principal para procesar la imagen y generar la receta
32
  def process_image(image):