Spaces:
Sleeping
Sleeping
| # 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 |