Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
#
|
7 |
hf_token = os.getenv("HF_TOKEN")
|
8 |
|
9 |
# Paso 1: Cargar el modelo de image-to-text
|
@@ -17,7 +17,7 @@ def generate_recipe(description):
|
|
17 |
url = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-72B-Instruct"
|
18 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
19 |
|
20 |
-
#
|
21 |
system_input = (
|
22 |
"Act as a professional chef. Your task is to explain to a regular person "
|
23 |
"how to cook a given dish, providing a step-by-step guide and a list of ingredients with exact quantities."
|
@@ -47,10 +47,10 @@ def generate_recipe(description):
|
|
47 |
if "error" in response_data:
|
48 |
return "Error generando receta: " + response_data["error"]
|
49 |
|
50 |
-
#
|
51 |
return response_data[0]["generated_text"].replace(prompt, "").strip() if response_data else "No se pudo generar la receta."
|
52 |
|
53 |
-
# Paso 4:
|
54 |
def process_image(image):
|
55 |
# Paso 4.1: Generar descripci贸n del plato
|
56 |
description = image_to_text(image)[0]['generated_text']
|
|
|
3 |
import requests
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# Obtener 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
|
|
|
17 |
url = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-72B-Instruct"
|
18 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
19 |
|
20 |
+
# A帽adir el system input para definir el rol del modelo
|
21 |
system_input = (
|
22 |
"Act as a professional chef. Your task is to explain to a regular person "
|
23 |
"how to cook a given dish, providing a step-by-step guide and a list of ingredients with exact quantities."
|
|
|
47 |
if "error" in response_data:
|
48 |
return "Error generando receta: " + response_data["error"]
|
49 |
|
50 |
+
# Devolver solo el texto generado sin el input del prompt
|
51 |
return response_data[0]["generated_text"].replace(prompt, "").strip() if response_data else "No se pudo generar la receta."
|
52 |
|
53 |
+
# Paso 4: Definir la funci贸n principal para procesar la imagen y generar la receta
|
54 |
def process_image(image):
|
55 |
# Paso 4.1: Generar descripci贸n del plato
|
56 |
description = image_to_text(image)[0]['generated_text']
|