Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,13 +29,25 @@ def get_ingredients_llama(food_name):
|
|
29 |
Returns a clean, comma-separated list of ingredients.
|
30 |
"""
|
31 |
prompt = (
|
32 |
-
f"List only the
|
33 |
-
"
|
34 |
)
|
35 |
try:
|
36 |
response = pipe_llama(prompt, max_length=50, num_return_sequences=1)
|
37 |
generated_text = response[0]["generated_text"].strip()
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# Process the response to ensure it's a clean, comma-separated list
|
40 |
ingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."
|
41 |
ingredients = ingredients.replace(".", "").strip() # Remove periods and extra spaces
|
|
|
29 |
Returns a clean, comma-separated list of ingredients.
|
30 |
"""
|
31 |
prompt = (
|
32 |
+
f"List only the ingredients for {food_name}. "
|
33 |
+
"Output the ingredients as a simple, comma-separated list such as: ingredient1, ingredient2, ingredient3."
|
34 |
)
|
35 |
try:
|
36 |
response = pipe_llama(prompt, max_length=50, num_return_sequences=1)
|
37 |
generated_text = response[0]["generated_text"].strip()
|
38 |
|
39 |
+
# Post-process to extract only the list of ingredients
|
40 |
+
ingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."
|
41 |
+
ingredients = ingredients.replace(".", "").strip() # Remove periods and extra spaces
|
42 |
+
|
43 |
+
# Ensure the response is a proper list format
|
44 |
+
if "," not in ingredients: # If the model didn't output a list, fallback to generic handling
|
45 |
+
ingredients = "No ingredients found or response unclear."
|
46 |
+
|
47 |
+
return ingredients
|
48 |
+
except Exception as e:
|
49 |
+
return f"Error generating ingredients: {e}"
|
50 |
+
|
51 |
# Process the response to ensure it's a clean, comma-separated list
|
52 |
ingredients = generated_text.split(":")[-1].strip() # Handle cases like "Ingredients: ..."
|
53 |
ingredients = ingredients.replace(".", "").strip() # Remove periods and extra spaces
|