pratikshahp commited on
Commit
5351ad1
·
verified ·
1 Parent(s): b52f779

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -9
app.py CHANGED
@@ -6,20 +6,12 @@ model = pipeline("text2text-generation", model="google/flan-t5-large")
6
  # Recipe generation function
7
  def suggest_recipes(ingredients):
8
  prompt = f"You are an expert in cooking. Please suggest 3 recipes using the following ingredients: {ingredients}. Provide a title for each recipe, include preparation time, and list step-by-step directions."
9
- response = model(prompt, max_length=512, num_return_sequences=3)
10
 
11
  # Parse model output into a structured format
12
  recipes = []
13
  for i, recipe in enumerate(response):
14
  text = recipe["generated_text"]
15
-
16
- # Split into meaningful sections for formatting
17
- lines = text.split("\n")
18
- title = f"Recipe {i+1}: {lines[0]}" if lines else f"Recipe {i+1}: Title Missing"
19
- prep_time = next((line for line in lines if "Preparation time" in line), "Preparation time: Not provided")
20
- directions = "\n".join([f"{idx+1}. {line}" for idx, line in enumerate(lines[1:]) if line])
21
-
22
- recipes.append(f"{title}\n{prep_time}\nDirections:\n{directions}\n\nReady to serve!")
23
 
24
  return "\n\n".join(recipes)
25
 
 
6
  # Recipe generation function
7
  def suggest_recipes(ingredients):
8
  prompt = f"You are an expert in cooking. Please suggest 3 recipes using the following ingredients: {ingredients}. Provide a title for each recipe, include preparation time, and list step-by-step directions."
9
+ response = model(prompt)
10
 
11
  # Parse model output into a structured format
12
  recipes = []
13
  for i, recipe in enumerate(response):
14
  text = recipe["generated_text"]
 
 
 
 
 
 
 
 
15
 
16
  return "\n\n".join(recipes)
17