krisha06 commited on
Commit
2a5d6eb
·
verified ·
1 Parent(s): ff65a9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -90,14 +90,21 @@ def answer_question(query, context=""):
90
 
91
  # Attempt to retrieve a recipe-related context
92
  related_recipes = retrieve_recipes(query, top_k=1)
93
- if related_recipes is not None and not related_recipes.empty:
94
- context = related_recipes.iloc[0]['instructions']
95
- else:
96
  return "I specialize in recipes! 🍽️ Feel free to ask me about ingredients, cooking methods, or meal ideas. 😊"
97
 
 
 
 
98
  # Generate an answer using the LLM
99
  response = llm_model(question=query, context=context)
100
- return response.get("answer", "I'm not sure, but I can help with recipes! What would you like to cook?").strip()
 
 
 
 
 
 
101
 
102
  # --- 8. Classify Query Type (Q&A or Recipe Search) ---
103
  @st.cache_resource
 
90
 
91
  # Attempt to retrieve a recipe-related context
92
  related_recipes = retrieve_recipes(query, top_k=1)
93
+ if related_recipes is None or related_recipes.empty:
 
 
94
  return "I specialize in recipes! 🍽️ Feel free to ask me about ingredients, cooking methods, or meal ideas. 😊"
95
 
96
+ # If a valid recipe is found, use its instructions as context
97
+ context = related_recipes.iloc[0]['instructions']
98
+
99
  # Generate an answer using the LLM
100
  response = llm_model(question=query, context=context)
101
+
102
+ # Ensure we only return meaningful answers
103
+ answer = response.get("answer", "").strip()
104
+ if not answer:
105
+ return "I'm not sure, but I can help with recipes! What would you like to cook?"
106
+
107
+ return answer
108
 
109
  # --- 8. Classify Query Type (Q&A or Recipe Search) ---
110
  @st.cache_resource