Team Ai
Apppublic

FaroukTomori/ai-programming-tutor

sourceHugging Faceotherupdated 1y agoView on Hugging Face
0likes
example_usage.py187 linesDownload Raw Back to src
1"""
2Example Usage of the Comprehensive Educational Feedback System
3"""
4
5from fine import ProgrammingEducationAI
6import json
7
8
9def main():
10    print("๐ŸŽ“ Comprehensive Educational Feedback System")
11    print("=" * 60)
12
13    # Initialize the system
14    # Update this path to your actual fine-tuned model
15    model_path = r"C:\Users\farou\OneDrive - Aston University\finetunning"
16    ai_tutor = ProgrammingEducationAI(model_path)
17
18    try:
19        # Load the model
20        print("Loading fine-tuned model...")
21        ai_tutor.load_model()
22        print("โœ… Model loaded successfully!")
23
24        # Example 1: Beginner student code
25        print("\n" + "="*60)
26        print("EXAMPLE 1: BEGINNER STUDENT")
27        print("="*60)
28
29        beginner_code = """
30def find_duplicates(numbers):
31    x = []
32    for i in range(len(numbers)):
33        for j in range(i+1, len(numbers)):
34            if numbers[i] == numbers[j]:
35                x.append(numbers[i])
36    return x
37
38result = find_duplicates([1, 2, 3, 2, 4, 5, 3])
39print(result)
40"""
41
42        print("Student Code:")
43        print(beginner_code)
44
45        feedback = ai_tutor.generate_comprehensive_feedback(
46            beginner_code, "beginner")
47        display_comprehensive_feedback(feedback)
48
49        # Example 2: Intermediate student code
50        print("\n" + "="*60)
51        print("EXAMPLE 2: INTERMEDIATE STUDENT")
52        print("="*60)
53
54        intermediate_code = """
55def fibonacci(n):
56    if n <= 1:
57        return n
58    return fibonacci(n-1) + fibonacci(n-2)
59
60# Calculate first 10 Fibonacci numbers
61for i in range(10):
62    print(fibonacci(i))
63"""
64
65        print("Student Code:")
66        print(intermediate_code)
67
68        feedback = ai_tutor.generate_comprehensive_feedback(
69            intermediate_code, "intermediate")
70        display_comprehensive_feedback(feedback)
71
72        # Example 3: Advanced student code
73        print("\n" + "="*60)
74        print("EXAMPLE 3: ADVANCED STUDENT")
75        print("="*60)
76
77        advanced_code = """
78class DataProcessor:
79    def __init__(self, data):
80        self.data = data
81    
82    def process(self):
83        result = []
84        for item in self.data:
85            if item > 0:
86                result.append(item * 2)
87        return result
88
89processor = DataProcessor([1, -2, 3, -4, 5])
90output = processor.process()
91print(output)
92"""
93
94        print("Student Code:")
95        print(advanced_code)
96
97        feedback = ai_tutor.generate_comprehensive_feedback(
98            advanced_code, "advanced")
99        display_comprehensive_feedback(feedback)
100
101    except Exception as e:
102        print(f"โŒ Error: {e}")
103        print(
104            "๐Ÿ’ก Make sure to update the model_path to point to your actual fine-tuned model.")
105
106
107def display_comprehensive_feedback(feedback):
108    """Display comprehensive feedback in a formatted way"""
109
110    print("\n๐Ÿ“Š COMPREHENSIVE FEEDBACK")
111    print("-" * 40)
112
113    # Analysis
114    print("\nโœ… STRENGTHS:")
115    for i, strength in enumerate(feedback.strengths, 1):
116        print(f"   {i}. {strength}")
117
118    print("\nโŒ WEAKNESSES:")
119    for i, weakness in enumerate(feedback.weaknesses, 1):
120        print(f"   {i}. {weakness}")
121
122    print("\nโš ๏ธ ISSUES:")
123    for i, issue in enumerate(feedback.issues, 1):
124        print(f"   {i}. {issue}")
125
126    # Educational content
127    print("\n๐Ÿ“ STEP-BY-STEP IMPROVEMENT:")
128    for i, step in enumerate(feedback.step_by_step_improvement, 1):
129        print(f"   Step {i}: {step}")
130
131    print("\n๐ŸŽ“ LEARNING POINTS:")
132    for i, point in enumerate(feedback.learning_points, 1):
133        print(f"   {i}. {point}")
134
135    print(f"\n๐Ÿ“‹ REVIEW SUMMARY:")
136    print(f"   {feedback.review_summary}")
137
138    # Interactive elements
139    print(f"\nโ“ COMPREHENSION QUESTION:")
140    print(f"   Q: {feedback.comprehension_question}")
141    print(f"   A: {feedback.comprehension_answer}")
142    print(f"   Explanation: {feedback.explanation}")
143
144    # Code fixes
145    print(f"\n๐Ÿ”ง IMPROVED CODE:")
146    print(feedback.improved_code)
147
148    print(f"\n๐Ÿ’ก FIX EXPLANATION:")
149    print(f"   {feedback.fix_explanation}")
150
151    # Metadata
152    print(f"\n๐Ÿ“Š METADATA:")
153    print(f"   Student Level: {feedback.student_level}")
154    print(f"   Learning Objectives: {', '.join(feedback.learning_objectives)}")
155    print(
156        f"   Estimated Time to Improve: {feedback.estimated_time_to_improve}")
157
158
159def save_feedback_to_json(feedback, filename):
160    """Save feedback to JSON file for later analysis"""
161    feedback_dict = {
162        "code_snippet": feedback.code_snippet,
163        "student_level": feedback.student_level,
164        "strengths": feedback.strengths,
165        "weaknesses": feedback.weaknesses,
166        "issues": feedback.issues,
167        "step_by_step_improvement": feedback.step_by_step_improvement,
168        "learning_points": feedback.learning_points,
169        "review_summary": feedback.review_summary,
170        "comprehension_question": feedback.comprehension_question,
171        "comprehension_answer": feedback.comprehension_answer,
172        "explanation": feedback.explanation,
173        "improved_code": feedback.improved_code,
174        "fix_explanation": feedback.fix_explanation,
175        "learning_objectives": feedback.learning_objectives,
176        "estimated_time_to_improve": feedback.estimated_time_to_improve
177    }
178
179    with open(filename, 'w') as f:
180        json.dump(feedback_dict, f, indent=2)
181
182    print(f"๐Ÿ’พ Feedback saved to {filename}")
183
184
185if __name__ == "__main__":
186    main()
187