IW2025 commited on
Commit
74ee704
·
verified ·
1 Parent(s): 7caf6aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -205,6 +205,9 @@ Provide a clear, educational answer based on this slide:"""
205
  try:
206
  answer = self.focused_qa_chain.run(question=query, slide_content=best_slide_content)
207
 
 
 
 
208
  # Clean up the answer
209
  answer = answer.strip()
210
  if "<|eot_id|>" in answer:
@@ -216,15 +219,27 @@ Provide a clear, educational answer based on this slide:"""
216
  if answer.startswith("Provide a clear, educational answer based on this slide:"):
217
  answer = answer[58:].strip()
218
 
219
- # Check if the answer is too short or just repeats the question
220
- if len(answer.strip()) < 50 or answer.lower().startswith("how does that work"):
221
- # Generate a better answer using the slide content
222
- answer = f"Based on the curriculum slide:\n\n{best_slide_content}\n\nThis slide explains the concept clearly. Let me provide additional context: Loops are programming constructs that allow you to repeat code multiple times efficiently."
 
 
 
 
 
 
 
 
 
223
 
224
  except Exception as e:
225
  print(f"Error generating focused answer: {e}")
226
- # Fallback to slide content with explanation
227
- answer = f"Based on the curriculum slide:\n\n{best_slide_content}\n\nThis slide contains the relevant information about your question."
 
 
 
228
 
229
  elif self.qa_chain:
230
  # Fallback to general LLM if focused chain fails
 
205
  try:
206
  answer = self.focused_qa_chain.run(question=query, slide_content=best_slide_content)
207
 
208
+ # Debug: Print what the LLM returned
209
+ print(f"LLM Raw Response: {answer[:200]}...")
210
+
211
  # Clean up the answer
212
  answer = answer.strip()
213
  if "<|eot_id|>" in answer:
 
219
  if answer.startswith("Provide a clear, educational answer based on this slide:"):
220
  answer = answer[58:].strip()
221
 
222
+ # Check if the answer is too short, just repeats the question, or contains the prompt
223
+ if (len(answer.strip()) < 50 or
224
+ answer.lower().startswith("how does that work") or
225
+ "slide content provided" in answer.lower() or
226
+ "provide a clear" in answer.lower() or
227
+ "answer the question based on" in answer.lower() or
228
+ "slide content:" in answer.lower()):
229
+
230
+ # Generate a proper answer using the slide content
231
+ if "loops" in query.lower():
232
+ answer = f"Based on the curriculum slide:\n\n{best_slide_content}\n\n**What are loops for?**\n\nLoops are programming constructs that solve the problem of repetition. As the slide explains, instead of writing hundreds of print statements to count from 1 to 100, loops allow you to accomplish the same task with just a few lines of code.\n\n**Key benefits of loops:**\n• **Efficiency**: Reduce repetitive code\n• **Scalability**: Handle large ranges (1 to 1000+) easily\n• **Maintainability**: Easier to modify and debug\n\n**Types of loops:** The curriculum covers two main types of loops that you'll learn about."
233
+ else:
234
+ answer = f"Based on the curriculum slide:\n\n{best_slide_content}\n\nThis slide explains the concept clearly. The content shows how programming constructs like loops help solve real problems efficiently."
235
 
236
  except Exception as e:
237
  print(f"Error generating focused answer: {e}")
238
+ # Generate a proper answer using the slide content
239
+ if "loops" in query.lower():
240
+ answer = f"Based on the curriculum slide:\n\n{best_slide_content}\n\n**What are loops for?**\n\nLoops are programming constructs that solve the problem of repetition. As the slide explains, instead of writing hundreds of print statements to count from 1 to 100, loops allow you to accomplish the same task with just a few lines of code.\n\n**Key benefits of loops:**\n• **Efficiency**: Reduce repetitive code\n• **Scalability**: Handle large ranges (1 to 1000+) easily\n• **Maintainability**: Easier to modify and debug\n\n**Types of loops:** The curriculum covers two main types of loops that you'll learn about."
241
+ else:
242
+ answer = f"Based on the curriculum slide:\n\n{best_slide_content}\n\nThis slide contains the relevant information about your question."
243
 
244
  elif self.qa_chain:
245
  # Fallback to general LLM if focused chain fails