Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,40 +28,37 @@ def generate_recipe(description):
|
|
28 |
payload = {
|
29 |
"inputs": prompt,
|
30 |
"parameters": {
|
31 |
-
"max_new_tokens": 1500,
|
32 |
-
"min_length": 500,
|
33 |
-
"temperature": 0.7,
|
34 |
-
"do_sample": True,
|
35 |
-
"repetition_penalty": 1.2,
|
36 |
-
"stop_sequences": ["\n\n"]
|
37 |
}
|
38 |
}
|
39 |
|
40 |
response = requests.post(url, headers=headers, json=payload)
|
41 |
response_data = response.json()
|
42 |
|
43 |
-
# Manejo de posibles errores
|
44 |
if "error" in response_data:
|
45 |
return "Error generating recipe: " + response_data["error"]
|
46 |
|
47 |
-
# Return only the generated text, without the input prompt
|
48 |
return response_data[0]["generated_text"].replace(prompt, "").strip() if response_data else "No recipe generated."
|
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=[
|
|
|
|
|
|
|
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 |
)
|
|
|
28 |
payload = {
|
29 |
"inputs": prompt,
|
30 |
"parameters": {
|
31 |
+
"max_new_tokens": 1500,
|
32 |
+
"min_length": 500,
|
33 |
+
"temperature": 0.7,
|
34 |
+
"do_sample": True,
|
35 |
+
"repetition_penalty": 1.2,
|
36 |
+
"stop_sequences": ["\n\n"]
|
37 |
}
|
38 |
}
|
39 |
|
40 |
response = requests.post(url, headers=headers, json=payload)
|
41 |
response_data = response.json()
|
42 |
|
|
|
43 |
if "error" in response_data:
|
44 |
return "Error generating recipe: " + response_data["error"]
|
45 |
|
|
|
46 |
return response_data[0]["generated_text"].replace(prompt, "").strip() if response_data else "No recipe generated."
|
47 |
|
48 |
# Paso 3: Define la funci贸n principal para procesar la imagen y generar la receta
|
49 |
def process_image(image):
|
|
|
50 |
description = image_to_text(image)[0]['generated_text']
|
|
|
|
|
51 |
recipe = generate_recipe(description)
|
|
|
52 |
return description, recipe
|
53 |
|
54 |
# Paso 4: Crear la interfaz de Gradio
|
55 |
iface = gr.Interface(
|
56 |
fn=process_image,
|
57 |
inputs=gr.Image(type="pil"),
|
58 |
+
outputs=[
|
59 |
+
gr.Textbox(label="Description"),
|
60 |
+
gr.Textbox(label="Recipe", lines=10, markdown=False) # Desactiva el formato Markdown
|
61 |
+
],
|
62 |
title="Recipe Generator from Dish Image",
|
63 |
description="Upload an image of a dish to get a description, ingredient list, and step-by-step recipe."
|
64 |
)
|