Azidan commited on
Commit
af3ae44
·
verified ·
1 Parent(s): 8c3fb35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -15,10 +15,10 @@ summarizer = pipeline(
15
  device=-1 # CPU only
16
  )
17
 
18
- # New AI advice generator - lightweight text2text model
19
  advice_generator = pipeline(
20
  "text2text-generation",
21
- model="google/flan-t5-small",
22
  device=-1 # CPU only
23
  )
24
 
@@ -56,21 +56,37 @@ def chunk_text(text: str):
56
 
57
  def generate_ai_advice(summary: str) -> str:
58
  """Use AI to generate personalized study advice based on the summary."""
59
- # Truncate summary if too long for the small model
60
- truncated_summary = summary[:800] # Safe limit for flan-t5-small
 
 
61
  prompt = (
62
- f"Based on this summary: {truncated_summary}\n"
63
- "Generate 5 concise study tips for a student to enhance learning and retention."
 
 
 
64
  )
65
- generated = advice_generator(prompt, max_length=200, num_return_sequences=1)[0]["generated_text"]
66
 
67
- # Format as markdown bullets
68
- tips = generated.split(". ") # Simple split assuming sentence-based output
 
 
 
 
 
 
 
 
 
 
 
69
  advice_md = "\n\n---\n\n### 📚 AI-Generated Study Tips\n\n"
70
- for tip in tips[:5]: # Limit to 5
71
- if tip.strip():
72
- advice_md += f"- {tip.strip()}.\n"
73
- advice_md += "\n**Pro tip**: Apply these tips consistently for better results!"
 
74
 
75
  return advice_md
76
 
 
15
  device=-1 # CPU only
16
  )
17
 
18
+ # Better AI advice generator - use flan-t5-base for improved quality (still CPU-friendly)
19
  advice_generator = pipeline(
20
  "text2text-generation",
21
+ model="google/flan-t5-base",
22
  device=-1 # CPU only
23
  )
24
 
 
56
 
57
  def generate_ai_advice(summary: str) -> str:
58
  """Use AI to generate personalized study advice based on the summary."""
59
+ # Truncate summary if too long
60
+ truncated_summary = summary[:1000] # Slightly longer for base model
61
+
62
+ # Improved prompt for better, more relevant tips
63
  prompt = (
64
+ f"Read this summary of a technical paper: '{truncated_summary}'\n\n"
65
+ "Generate exactly 5 practical study tips for a student to better understand and retain this content. "
66
+ "Focus on active learning techniques, like practice, visualization, or connections to real-world applications. "
67
+ "Make each tip start with a verb (e.g., 'Review...', 'Apply...') and keep them concise. "
68
+ "Output only the 5 tips as bullet points, nothing else."
69
  )
 
70
 
71
+ generated = advice_generator(
72
+ prompt,
73
+ max_length=250,
74
+ num_return_sequences=1,
75
+ do_sample=False, # Greedy for consistency
76
+ temperature=0.7 # Slight creativity if needed
77
+ )[0]["generated_text"]
78
+
79
+ # Post-process to ensure bullet format
80
+ tips = [tip.strip() for tip in generated.split('\n') if tip.strip().startswith('-') or tip.strip()]
81
+ if not tips:
82
+ tips = generated.split('. ') # Fallback split
83
+
84
  advice_md = "\n\n---\n\n### 📚 AI-Generated Study Tips\n\n"
85
+ for i, tip in enumerate(tips[:5], 1):
86
+ clean_tip = tip.lstrip('- ').strip()
87
+ advice_md += f"- {clean_tip}\n"
88
+
89
+ advice_md += "\n**Pro tip**: Combine these with spaced repetition for long-term mastery!"
90
 
91
  return advice_md
92