Spaces:
Sleeping
Sleeping
File size: 2,665 Bytes
526fa24 3aabd8c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | # Enhanced QuizAgent in ai/agents.py
class QuizAgent(Agent):
def __init__(self, hf_service):
super().__init__("Quiz", "Generates questions")
self.hf = hf_service
def process(self, content, context=None):
# Generate 3-5 questions based on content
questions = []
# Extract key concepts using summarization
summary = self.hf.summarize_content(content)[0]['summary_text']
# Generate questions using question-answering in reverse
# We'll extract potential answers and create questions for them
sentences = summary.split('. ')
for sentence in sentences[:5]: # Limit to 5 questions
# Use the sentence as context and try to generate a question
potential_answer = sentence.strip()
# We'll need to integrate with a better question generation model here
# For now, create a simple question by masking parts of the sentence
words = potential_answer.split()
if len(words) > 5:
# Find a key noun or entity to ask about
# This is simplified - would need NER or POS tagging in production
question_word = words[len(words)//2]
question = potential_answer.replace(question_word, "___")
questions.append({
"question": f"Complete the following: {question}",
"answer": question_word,
"context": potential_answer
})
return questions
# New PersonalizationAgent in ai/agents.py
class PersonalizationAgent(Agent):
def __init__(self, hf_service):
super().__init__("Personalizer", "Adapts content for users")
self.hf = hf_service
def process(self, content, context=None):
# Context should contain user profile/level
if not context or 'level' not in context:
return content
user_level = context['level']
if user_level == 'beginner':
# Simplify content, add more explanations
simplified = self.hf.summarize_content(
content,
max_length=len(content.split()) // 2 # Half the original length
)[0]['summary_text']
return f"{simplified}\n\nLet's break this down further: {content}"
elif user_level == 'advanced':
# Provide more detailed content
return f"{content}\n\nFor advanced learners: [Additional depth would be added here]"
# Default - intermediate
return content |