Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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")
|
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":
|
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 |
-
|
|
|
|
|
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):
|