Download model/teaching.py from hackerbhai/vinaymodel: direct link, hf CLI and curl.
- Browser
- Download file 7.98 kB
-
https://huggingface.co/hackerbhai/vinaymodel/resolve/main/model/teaching.py
- Command line
-
hf download hf://hackerbhai/vinaymodel/model/teaching.py
-
curl -L -o teaching.py https://huggingface.co/hackerbhai/vinaymodel/resolve/main/model/teaching.py
7.98 kB
| """ | |
| Teaching Mode - Interactive learning with mistake detection | |
| """ | |
| from typing import Dict, List, Optional | |
| from .memory import MemorySystem, EnglishMistakeDetector, ConversationStyle | |
| class TeachingMode: | |
| """Interactive teaching with mistake detection and friendly conversation""" | |
| def __init__(self, user_id: str = "default", style: str = "friend"): | |
| self.user_id = user_id | |
| self.memory = MemorySystem(user_id) | |
| self.mistake_detector = EnglishMistakeDetector() | |
| self.conversation_style = ConversationStyle(style) | |
| self.current_topic = None | |
| self.lesson_progress = {} | |
| def start_lesson(self, topic: str) -> Dict: | |
| """Start a new lesson""" | |
| self.current_topic = topic | |
| self.lesson_progress = { | |
| 'topic': topic, | |
| 'started': True, | |
| 'mistakes': 0, | |
| 'corrections': 0, | |
| 'examples_practiced': 0 | |
| } | |
| greeting = self.conversation_style.get_response('greeting') | |
| topic_intros = { | |
| 'english': f"{greeting}\n\nLet's practice English together! I'll help you with grammar, vocabulary, and conversation. Just write anything in English and I'll help you improve! ๐", | |
| 'grammar': f"{greeting}\n\nLet's work on English grammar! I'll teach you tenses, articles, prepositions, and more. Try writing some sentences! โ๏ธ", | |
| 'vocabulary': f"{greeting}\n\nLet's build your vocabulary! I'll teach you new words and how to use them. Try using new words in sentences! ๐", | |
| 'conversation': f"{greeting}\n\nLet's practice conversation! Just talk to me like a friend, and I'll help you sound more natural. ๐ฌ", | |
| 'hindi': f"{greeting}\n\nLet's practice Hindi! Main aapki madad karunga Hindi seekhne mein. Hindi mein kuch likhiye! ๐ฎ๐ณ", | |
| 'math': f"{greeting}\n\nLet's solve math problems together! Show me what you're working on, and I'll help you step by step. ๐ข" | |
| } | |
| intro = topic_intros.get(topic.lower(), f"{greeting}\n\nLet's learn {topic} together! I'm here to help you. What would you like to start with?") | |
| return { | |
| 'response': intro, | |
| 'topic': topic, | |
| 'status': 'started' | |
| } | |
| def process_input(self, user_input: str) -> Dict: | |
| """Process user input and provide feedback""" | |
| response = { | |
| 'original_input': user_input, | |
| 'mistakes_found': [], | |
| 'corrections': [], | |
| 'feedback': '', | |
| 'encouragement': '', | |
| 'next_step': '' | |
| } | |
| # Detect mistakes if it's English practice | |
| if self.current_topic and self.current_topic.lower() in ['english', 'grammar', 'conversation', 'vocabulary']: | |
| mistakes = self.mistake_detector.detect_mistakes(user_input) | |
| if mistakes: | |
| response['mistakes_found'] = mistakes | |
| # Create corrections | |
| for mistake in mistakes: | |
| correction_msg = self.conversation_style.format_correction( | |
| mistake['original'], | |
| mistake['correction'], | |
| self.mistake_detector.get_explanation(mistake) | |
| ) | |
| response['corrections'].append(correction_msg) | |
| # Record mistake in memory | |
| self.memory.add_mistake( | |
| mistake['original'], | |
| mistake['correction'], | |
| mistake['type'], | |
| self.current_topic | |
| ) | |
| response['feedback'] = f"I found {len(mistakes)} mistake(s). Let me help you fix them! ๐ช" | |
| else: | |
| response['feedback'] = self.conversation_style.get_response('encouragement') | |
| response['next_step'] = "Your sentence is perfect! Try another one or ask me anything." | |
| # Store conversation in memory | |
| full_response = response['feedback'] | |
| if response['corrections']: | |
| full_response += "\n\n" + "\n".join(response['corrections']) | |
| self.memory.add_conversation(user_input, full_response, self.current_topic or '') | |
| return response | |
| def get_learning_summary(self) -> Dict: | |
| """Get user's learning summary""" | |
| stats = self.memory.get_user_stats() | |
| weak_areas = self.memory.get_weak_areas() | |
| learned = self.memory.get_learned_topics() | |
| common_mistakes = self.memory.get_common_mistakes(top_n=3) | |
| summary = f""" | |
| ๐ **Your Learning Progress** | |
| โ Topics Learned: {len(learned)} | |
| ๐ฏ Weak Areas: {len(weak_areas)} | |
| โ๏ธ Corrections Made: {stats['corrections_made']} | |
| ๐ฌ Conversations: {stats['total_conversations']} | |
| ๐ Progress: {stats['learning_progress']:.1f}% | |
| """ | |
| if weak_areas: | |
| summary += f"๐ Focus Areas: {', '.join(weak_areas[:3])}\n" | |
| if common_mistakes: | |
| summary += "\n๐ Common Mistakes to Work On:\n" | |
| for mistake in common_mistakes: | |
| summary += f" โข '{mistake['mistake']}' (appeared {mistake['count']} times)\n" | |
| if learned: | |
| summary += f"\n๐ Great Job! You've learned: {', '.join(learned[:5])}" | |
| return { | |
| 'summary': summary, | |
| 'stats': stats, | |
| 'weak_areas': weak_areas, | |
| 'learned_topics': learned | |
| } | |
| def set_style(self, style: str): | |
| """Change conversation style""" | |
| self.conversation_style = ConversationStyle(style) | |
| self.memory.set_preference('conversation_style', style) | |
| return f"Sure! I'll talk to you as your {style} now! ๐" | |
| def check_progress(self, topic: str = None) -> Dict: | |
| """Check user's progress in a topic""" | |
| topic = topic or self.current_topic | |
| if not topic: | |
| return {'error': 'No topic selected. Start a lesson first!'} | |
| improvement = self.memory.check_improvement(topic) | |
| mistakes = self.memory.get_mistake_history(topic) | |
| return { | |
| 'topic': topic, | |
| 'total_mistakes': len(mistakes), | |
| 'improvement': improvement, | |
| 'message': improvement['message'] | |
| } | |
| def get_personalized_lesson(self) -> Dict: | |
| """Get a personalized lesson based on weak areas""" | |
| weak_areas = self.memory.get_weak_areas() | |
| if not weak_areas: | |
| return { | |
| 'response': "You're doing great! No specific weak areas found. Let's practice something new! What topic interests you?", | |
| 'suggestion': 'new_topic' | |
| } | |
| # Pick the most common weak area | |
| focus_area = weak_areas[0] | |
| lesson_suggestions = { | |
| 'tense': "I noticed you sometimes struggle with tenses. Let's practice past tense! Can you tell me what you did yesterday?", | |
| 'article': "Let's work on articles (a, an, the). Try writing 3 sentences about your day, and I'll help with articles!", | |
| 'preposition': "Prepositions can be tricky! Let's practice common ones: in, on, at. Tell me where things are in your room.", | |
| 'subject-verb agreement': "Let's practice matching subjects with verbs. Try: 'He/She/It ___' and fill in the blank!", | |
| 'indian_english': "Let's work on standard English expressions. I'll give you common phrases and we'll practice the natural way to say them!" | |
| } | |
| suggestion = lesson_suggestions.get(focus_area, f"Let's work on {focus_area}. Ready to practice?") | |
| return { | |
| 'response': suggestion, | |
| 'focus_area': focus_area, | |
| 'suggestion': 'personalized_practice' | |
| } | |