File size: 5,627 Bytes
5fffedf |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
"""
Example Usage of the Comprehensive Educational Feedback System
"""
from fine import ProgrammingEducationAI
import json
def main():
print("๐ Comprehensive Educational Feedback System")
print("=" * 60)
# Initialize the system
# Update this path to your actual fine-tuned model
model_path = r"C:\Users\farou\OneDrive - Aston University\finetunning"
ai_tutor = ProgrammingEducationAI(model_path)
try:
# Load the model
print("Loading fine-tuned model...")
ai_tutor.load_model()
print("โ
Model loaded successfully!")
# Example 1: Beginner student code
print("\n" + "="*60)
print("EXAMPLE 1: BEGINNER STUDENT")
print("="*60)
beginner_code = """
def find_duplicates(numbers):
x = []
for i in range(len(numbers)):
for j in range(i+1, len(numbers)):
if numbers[i] == numbers[j]:
x.append(numbers[i])
return x
result = find_duplicates([1, 2, 3, 2, 4, 5, 3])
print(result)
"""
print("Student Code:")
print(beginner_code)
feedback = ai_tutor.generate_comprehensive_feedback(
beginner_code, "beginner")
display_comprehensive_feedback(feedback)
# Example 2: Intermediate student code
print("\n" + "="*60)
print("EXAMPLE 2: INTERMEDIATE STUDENT")
print("="*60)
intermediate_code = """
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
# Calculate first 10 Fibonacci numbers
for i in range(10):
print(fibonacci(i))
"""
print("Student Code:")
print(intermediate_code)
feedback = ai_tutor.generate_comprehensive_feedback(
intermediate_code, "intermediate")
display_comprehensive_feedback(feedback)
# Example 3: Advanced student code
print("\n" + "="*60)
print("EXAMPLE 3: ADVANCED STUDENT")
print("="*60)
advanced_code = """
class DataProcessor:
def __init__(self, data):
self.data = data
def process(self):
result = []
for item in self.data:
if item > 0:
result.append(item * 2)
return result
processor = DataProcessor([1, -2, 3, -4, 5])
output = processor.process()
print(output)
"""
print("Student Code:")
print(advanced_code)
feedback = ai_tutor.generate_comprehensive_feedback(
advanced_code, "advanced")
display_comprehensive_feedback(feedback)
except Exception as e:
print(f"โ Error: {e}")
print(
"๐ก Make sure to update the model_path to point to your actual fine-tuned model.")
def display_comprehensive_feedback(feedback):
"""Display comprehensive feedback in a formatted way"""
print("\n๐ COMPREHENSIVE FEEDBACK")
print("-" * 40)
# Analysis
print("\nโ
STRENGTHS:")
for i, strength in enumerate(feedback.strengths, 1):
print(f" {i}. {strength}")
print("\nโ WEAKNESSES:")
for i, weakness in enumerate(feedback.weaknesses, 1):
print(f" {i}. {weakness}")
print("\nโ ๏ธ ISSUES:")
for i, issue in enumerate(feedback.issues, 1):
print(f" {i}. {issue}")
# Educational content
print("\n๐ STEP-BY-STEP IMPROVEMENT:")
for i, step in enumerate(feedback.step_by_step_improvement, 1):
print(f" Step {i}: {step}")
print("\n๐ LEARNING POINTS:")
for i, point in enumerate(feedback.learning_points, 1):
print(f" {i}. {point}")
print(f"\n๐ REVIEW SUMMARY:")
print(f" {feedback.review_summary}")
# Interactive elements
print(f"\nโ COMPREHENSION QUESTION:")
print(f" Q: {feedback.comprehension_question}")
print(f" A: {feedback.comprehension_answer}")
print(f" Explanation: {feedback.explanation}")
# Code fixes
print(f"\n๐ง IMPROVED CODE:")
print(feedback.improved_code)
print(f"\n๐ก FIX EXPLANATION:")
print(f" {feedback.fix_explanation}")
# Metadata
print(f"\n๐ METADATA:")
print(f" Student Level: {feedback.student_level}")
print(f" Learning Objectives: {', '.join(feedback.learning_objectives)}")
print(
f" Estimated Time to Improve: {feedback.estimated_time_to_improve}")
def save_feedback_to_json(feedback, filename):
"""Save feedback to JSON file for later analysis"""
feedback_dict = {
"code_snippet": feedback.code_snippet,
"student_level": feedback.student_level,
"strengths": feedback.strengths,
"weaknesses": feedback.weaknesses,
"issues": feedback.issues,
"step_by_step_improvement": feedback.step_by_step_improvement,
"learning_points": feedback.learning_points,
"review_summary": feedback.review_summary,
"comprehension_question": feedback.comprehension_question,
"comprehension_answer": feedback.comprehension_answer,
"explanation": feedback.explanation,
"improved_code": feedback.improved_code,
"fix_explanation": feedback.fix_explanation,
"learning_objectives": feedback.learning_objectives,
"estimated_time_to_improve": feedback.estimated_time_to_improve
}
with open(filename, 'w') as f:
json.dump(feedback_dict, f, indent=2)
print(f"๐พ Feedback saved to {filename}")
if __name__ == "__main__":
main()
|